

<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<meta http-equiv="X-UA-Compatible" content="IE=edge">
	<meta name="viewport" content="width=device-width, initial-scale=1.0">
	<title>Document</title>
</head>
<body>

	<style>
.main-tut-content {
   background: white;
   color: black;
   padding: 1em;
   border-radius: 0.5em;
}
.main-tut-content a{
   color: blue;
}
</style>
<div class="main-tut-content">
<h1 style="color: black">JassHelper 0.A.2.B</h1>
<style type="text/css"><!--

.syntax-NULL {
  color: #010101;
}
.syntax-COMMENT1 {
  color: #0f6601;
  font-style: italic;
}
.syntax-COMMENT2 {
  background: #f7fef7;
  color: #016f0b;
  font-style: italic;
}
.syntax-COMMENT3 {
  color: #8e8e8e;
  font-weight: bold;
}
.syntax-COMMENT4 {
  color: #cc6600;
}
.syntax-DIGIT {
  color: #000066;
}
.syntax-FUNCTION {
  color: #ff7200;
}
.syntax-INVALID {
  background: #ff0f00;
  color: #fefefe;
}
.syntax-KEYWORD1 {
  color: #190090;
  font-weight: bold;
}
.syntax-KEYWORD2 {
  color: #010101;
  font-weight: bold;
}
.syntax-KEYWORD3 {
  color: #6868fd;
  font-weight: bold;
}
.syntax-KEYWORD4 {
  color: #ff3900;
}
.syntax-LABEL {
  color: #02b902;
}
.syntax-LITERAL1 {
  color: #ae01a3;
  font-style: italic;
}
.syntax-LITERAL2 {
  color: #000066;
}
.syntax-LITERAL3 {
  color: #cc0096;
}
.syntax-LITERAL4 {
  color: #2d00ff;
}
.syntax-MARKUP {
  color: #0000ff;
}
.syntax-OPERATOR {
  color: #016241;
  font-weight: bold;
}


-->
</style>
<p>Although World Editor's Jass compiler was finally replaced by PJass using WEHelper , there were a couple of other annoyances that still needed fixing, that's the reason this project begand.</p>

<p>Later I felt like going further and restarted the idea of extending Jass to OOP thus JassHelper is a compiler for the vJass language extension which includes structs, libraries, textmacros and more.</p>

<p>Although this is not really OOP the syntax is powerful enough I hope, there is no inheritance and that's the reason I am not calling the objects classes but structs. There are however, interfaces which allow polymorphism and since they can declare attributes you can have some kind of pseudo inheritance. Pseudo inheritance can be accomplished in many ways.</p>

<p>The design of vJass ought to stay static eventually so I stop adding syntax construct cause that' the right thing to do. After version 1.0.0 there should not be any addition, so if you have requests hurry up cause it would not be healthy to change the syntax after 1.0.0.</p>

<p>Version Z.0 introduces the addition of the Zinc language to jasshelper, it is just a less verbose alternative to vJass that is also more rigid on some aspects.</p>

<h2 style="color: black">Table of contents</h2>

<h3 style="color: black">I. vJass reference:</h3>

<ul>
	<li>Jass syntax mods</li>
</ul>

<ul>
	<li><a href="#gdf">Global declaration freedom</a></li>
	<li><a href="#ndf">Native declaration freedom</a></li>
	<li><a href="#debp">Debug preprocessor</a></li>
	<li><a href="#shadowing">Local variables shadowing</a></li>
	<li><a href="#retfix">Patch 1.24 return bug false positive fixer</a></li>
</ul>

<ul>
	<li>Entry preprocessors</li>
</ul>

<ul>
	<li><a href="#import">Import external script files</a></li>
	<li><a href="#zinc">Zinc</a></li>
	<li><a href="#novjass">No vJass!</a></li>
</ul>

<ul>
	<li>Libraries and Scopes
	<ul>
		<li><a href="#lib">Libraries</a></li>
		<li><a href="#priv">Private members, scopes</a></li>
		<li><a href="#pub">Public members</a></li>
		<li><a href="#nests">Nested scopes</a></li>
		<li><a href="#sconst">SCOPE_PREFIX and SCOPE_PRIVATE</a></li>
		<li><a href="#keyword">keyword</a></li>
	</ul>
	</li>
	<li><a href="#textm">TextMacros</a></li>
	<li>Structs and other custom types
	<ul>
		<li><a href="#stru">Structs</a></li>
		<li><a href="#strudecl">Declaring structs</a></li>
		<li><a href="#strucrest">Creating and destroying structs</a></li>
		<li><a href="#strucuse">Struct usage</a></li>
		<li><a href="#strucins">Instance members</a></li>
		<li><a href="#strucglob">Globals of struct types</a></li>
		<li><a href="#strucstat">Static members</a></li>
		<li><a href="#strucpubriv">public/private structs</a></li>
		<li><a href="#strucmeth">Methods</a></li>
		<li><a href="#strucenc">Encapsullation</a></li>
		<li><a href="#strucmethstac">Static methods</a></li>
		<li><a href="#strucondes">The onDestroy method</a></li>
		<li><a href="#struconini">The onInit method</a></li>
		<li><a href="#interfs">Interfaces</a></li>
		<li><a href="#operover">Operator making</a></li>
		<li><a href="#extendstruct">Extending structs</a></li>
		<li><a href="#stubmeth">Stub methods</a></li>
		<li><a href="#super">super</a></li>
		<li><a href="#dynarr">Dynamic arrays</a></li>
		<li><a href="#arrmemb">Array members</a></li>
		<li><a href="#delegat">Delegate</a></li>
		<li><a href="#thistype">thistype</a></li>
		<li><a href="#module">Module</a></li>
		<li><a href="#funcobj">Functions as objects</a></li>
		<li><a href="#funcinterf">Function interfaces</a></li>
		<li><a href="#typecast">Typecast</a></li>
		<li><a href="#methodname">Method function name</a></li>
		<li><a href="#methodexists">Method exists</a></li>
		<li><a href="#arrstruct">Array structs</a></li>
		<li><a href="#keykeykey">Keys</a></li>
	</ul>
	</li>
	<li>Storage space enhancements
	<ul>
		<li><a href="#storintro">Introduction</a></li>
		<li><a href="#storarray">Sized arrays</a></li>
		<li><a href="#twodarray">2D arrays</a></li>
		<li><a href="#storstruct">Structs with more index space</a></li>
		<li><a href="#stordyrar">Dynamic arrays with more index space</a></li>
	</ul>
	</li>
	<li>Jass syntax extensions</li>
</ul>

<ul>
	<li><a href="#secolon">Colon</a></li>
	<li><a href="#delicom">Delimited comments</a></li>
	<li>Comma (Not implemented yet)</li>
</ul>

<ul>
	<li><a href="#hook">hook</a></li>
	<li><a href="#inject">inject</a></li>
	<li><a href="#slk">Loading structs from SLK files</a></li>
	<li><a href="#opt">Script optimization</a></li>
</ul>

<ul>
	<li><a href="#inl">Function inlining</a></li>
</ul>

<ul>
	<li><a href="#ext">External tools</a></li>
	<li><a href="#br">Linebreak fixer</a></li>
</ul>

<h3 style="color: black"><a href="#inst">II. Installation</a></h3>

<ul>
	<li><a href="#platplat">Supported platforms</a></li>
</ul>

<h3 style="color: black"><a href="#usag">III. Usage</a></h3>

<ul>
	<li><a href="#usagnewg">Newgen pack</a></li>
	<li><a href="#usagcli">Command line</a>
	<ul>
		<li><a href="#clidebug">--debug</a></li>
		<li><a href="#clinopre">--nopreprocessor</a></li>
		<li><a href="#clinoop">--nooptimize</a></li>
		<li><a href="#clifile">--scriptonly</a></li>
		<li><a href="#cliwar">--warcity</a></li>
		<li><a href="#clizinc">--zinconly</a></li>
		<li><a href="#climac">--macromode</a></li>
		<li><a href="#cliabout">--about</a></li>
		<li><a href="#clierror">--showerrors</a></li>
		<li><a href="#clicli">clijasshelper.exe</a></li>
	</ul>
	</li>
</ul>

<h2 style="color: black">I. vJass reference:</h2>

<p>If you want actual instructions on how to install and use JassHelper: <a href="#installing">skip to the usage area</a>, remember to come back here once you have it installed so you can actually take advantage of this solution.</p>

<h3 style="color: black"><a name="gdf"></a>Global declaration Freedom</h3>

<p>Warcraft III world editor always made everything harder for us, inluding declaring globals, you needed to use that dialog and it was really difficult to recreate global variables from a map or another and you were forced to use GUI for that. It was also impossible to declare globals of some types without modding world editor and then make your map completelly unopenable by normal world editor.</p>

<p>Global declaration freedom simply allows you to write globals blocks wherever you want, for example in the custom script section or in a 'trigger', and because of this you can even use the constant prefix which can even make finalizers able to inline constants and stuff.</p>

<p>The JassHelper preprocessor will simply merge all the global blocks found around the map script and move them to the top of the map, all merged in a single globals block.</p>

<pre><span class="syntax0"><span class="syntax-KEYWORD2">function</span> something <span class="syntax-KEYWORD2">takes</span> <span class="syntax-KEYWORD3">nothing</span> <span class="syntax-KEYWORD2">returns</span> <span class="syntax-KEYWORD3">nothing</span>
    <span class="syntax-KEYWORD1">set</span> somearray<span class="syntax-OPERATOR">[</span>SOMETHING_INDEX<span class="syntax-OPERATOR">]</span><span class="syntax-OPERATOR">=</span><span class="syntax-DIGIT">4</span>
<span class="syntax-KEYWORD2">endfunction</span>

<span class="syntax-KEYWORD2">globals</span>
    <span class="syntax-KEYWORD2">constant</span> <span class="syntax-KEYWORD3">integer</span> SOMETHING_INDEX <span class="syntax-OPERATOR">=</span> <span class="syntax-DIGIT">45</span>
    <span class="syntax-KEYWORD3">integer</span> <span class="syntax-KEYWORD3">array</span> somearray
<span class="syntax-KEYWORD2">endglobals</span>

</span></pre>

<p>Will now work without any error, there is one limitation though, you can't use functions or non-constant values in the default value, for example you can make a global start on null, 1 , 19923 , 0xFFF, true, false, "Hi" , etc. But you can't make them initialize with any function call or with a native (although it is possible to use a native, most natives tend to crash the thread when used in globals declaration). You can't also assign to another global variable, because there isn't really a way to control to what position of the map would a global declaration go.</p>

<h4 style="color: black">Notes:</h4>

<ul>
	<li>Please try to keep a good global naming method, some programs use pure caps for global names, Jass' standard set by common.j and blizzard.j is that constants should be uppercase, you can then use system_variable for a good variable name, although you can stick to the udg_ preffix as well.</li>
</ul>

<h3 style="color: black"><a name="ndf"></a>Native declaration Freedom</h3>

<p>This feature (added in 0.9.I.0) is similar to global declarations, but it is for more advanced users, so if you do not understand a single thing of these few paragraphs, feel free to skip to the explanation about the debug keyword. Warcraft III supports declaration of natives in the map script, but it requires the natives to be declared just after the script's globals section. Jasshelper will detect these declarations along the map and move them to the correct place.</p>

<p>Why would you want to do this? And what native functions exactly? There are some few native functions that were created for AI scripts that are not declared in common.j, some of them are actually useful for Jass maps. There is also the possibility you are using a modded/hacked version of warcraft III, and importing a whole new common.j for the native functions is probably too annoying for you, in this case you can declare the new custom functions in the map as well.</p>

<p>There is a protection in this feature that will make jasshelper delete declarations of duplicate natives. (i.e if the native was already declared in common.j, it will remove the native from the map script, to ensure your map is actually playable). This heavily depends on the common.j version provided to jasshelper. This is something to consider if for some reason the common.j version you (or newgen pack) is passing to jasshelper is different to the common.j version you intend the map to be playable with.</p>

<pre><span class="syntax0"><span class="syntax-KEYWORD2">native</span> GetUnitGoldCost <span class="syntax-KEYWORD2">takes</span> <span class="syntax-KEYWORD3">integer</span> unitid <span class="syntax-KEYWORD2">returns</span> <span class="syntax-KEYWORD3">integer</span>

<span class="syntax-KEYWORD2">function</span> test <span class="syntax-KEYWORD2">takes</span> <span class="syntax-KEYWORD3">nothing</span> <span class="syntax-KEYWORD2">returns</span> <span class="syntax-KEYWORD3">nothing</span>
    <span class="syntax-KEYWORD1">call</span> <span class="syntax-FUNCTION">BJDebugMsg</span><span class="syntax-OPERATOR">(</span><span class="syntax-LITERAL1">"</span><span class="syntax-LITERAL1">A</span><span class="syntax-LITERAL1"> </span><span class="syntax-LITERAL1">footman</span><span class="syntax-LITERAL1"> </span><span class="syntax-LITERAL1">consts</span><span class="syntax-LITERAL1"> </span><span class="syntax-LITERAL1">:</span><span class="syntax-LITERAL1"> </span><span class="syntax-LITERAL1">"</span><span class="syntax-OPERATOR">+</span><span class="syntax-KEYWORD4">I2S</span><span class="syntax-OPERATOR">(</span> GetUnitGoldCost<span class="syntax-OPERATOR">(</span><span class="syntax-LITERAL1">'hfoo'</span><span class="syntax-OPERATOR">)</span><span class="syntax-OPERATOR">+</span><span class="syntax-LITERAL1">"</span><span class="syntax-LITERAL1"> </span><span class="syntax-LITERAL1">gold</span><span class="syntax-LITERAL1"> </span><span class="syntax-LITERAL1">coins</span><span class="syntax-LITERAL1">"</span> <span class="syntax-OPERATOR">)</span> <span class="syntax-OPERATOR">)</span>
<span class="syntax-KEYWORD2">endfunction</span>

</span></pre>

<h3 style="color: black"><a name="debp"></a>Debug preprocessor</h3>

<p>Jass includes a debug keyword which compiles correctly but makes the rest of the code be ignored. It seemed this keyword was used for debugging purposes like a switch in a debug build of warcraft III that enabled those calls.</p>

<p>We can now take advantage of this hidden Jass feature. Saving a map in debug mode using JassHelper will simply remove the debug keyword so the calls are enabled, if debug mode is not enabled, JassHelper will remove the lines that begin with debug.</p>

<pre><span class="syntax0"><span class="syntax-KEYWORD2">function</span> Something <span class="syntax-KEYWORD2">takes</span> <span class="syntax-KEYWORD3">integer</span> a <span class="syntax-KEYWORD2">returns</span> <span class="syntax-KEYWORD3">nothing</span>
   <span class="syntax-KEYWORD1">debug</span> <span class="syntax-KEYWORD1">call</span> <span class="syntax-FUNCTION">BJDebugMsg</span><span class="syntax-OPERATOR">(</span><span class="syntax-LITERAL1">"</span><span class="syntax-LITERAL1">a</span><span class="syntax-LITERAL1"> </span><span class="syntax-LITERAL1">is</span><span class="syntax-LITERAL1"> </span><span class="syntax-LITERAL1">"</span><span class="syntax-OPERATOR">+</span><span class="syntax-KEYWORD4">I2S</span><span class="syntax-OPERATOR">(</span>a<span class="syntax-OPERATOR">)</span><span class="syntax-OPERATOR">)</span>
   <span class="syntax-KEYWORD1">call</span> KillNUnits<span class="syntax-OPERATOR">(</span>a<span class="syntax-OPERATOR">)</span>
<span class="syntax-KEYWORD2">endfunction</span>

</span></pre>

<p>If we use this function in a map saved with debug mode, we will see "a is value" each time this function is called, otherwise it will only call KillNUnits silently.</p>

<p>You may also use the constant boolean DEBUG_MODE which is set to true or false depending on whether the debug mode is enabled.</p>

<h3 style="color: black"><a name="shadowing"></a>Local variables shadowing</h3>

<p>Starting with version 0.9.K.0, local variable shadowing is part of vJass syntax, unlike Jass syntax in which it has always been a problem. Up to patch 1.24, it was not even possible to shadow more than one variable, and it turned the whole map script into case-insensitive. These glitches were apparently fixed around patch 1.24, but they were fixed barely to a level of helping GUI users do local var tricks. Issues persist, and the issues are of the kind that could eventually cause some scripts issues in unpredictable places.</p>

<p>If the vJass code is used correctly and things are correctly scoped, this should not be a problem. However, when using code from multiple places, one of the codes may not be correctly scoped, which threatens to cause a conflict with a local variable and thus then making your map mysteriously unopenable in wc3. Jass' weakness with variable shadowing was too unpredictable in nature. So I decided to add a small preprocessor phase to jasshelper that will simulate correct local variable shadowing. This means that the local variables in your functions may now have the same name as any global in the map (even globals you do not know about) without causing further issues or unknown, unpredictable bugs (unlike normal Jass in which this is an active possibility). Although the vJass code allows variable shadowing, it is compiled to Jass code in which there is no shadowing (some l__ prefixes are added to conflicting local variables).</p>

<h3 style="color: black"><a name="retfix"></a>Patch 1.24 return bug false positive fixer</h3>

<p><b>Note:</b> This feature is disabled by default as the problems were fixed by patch 1.24b.</p>

<p>Retail patch 1.24 brought a lot of doom and destruction to the world of Jass, thanks to some new blizzard bugs, certain functions with more than one return statement would silent cause syntax errors or crash the game, effectively making innocent maps unplayable, even if they do not use the now infamous &amp;aquot;Return bug exploiters&amp;aquot;. This was the reason, that I had to add a quick fix to jasshelper, this compiler mod will replace all your functions with multiple return values into two separate functions that will be safe from the false positive.</p>

<h4 style="color: black">Side effects and limitations</h4>

<p>This fixer is only meant as a temporary measure while blizzard fixes this terrible bug or while you make your functions safe from having multiple return statements, whatever happens first. The technique is a little dumb, for each function that is suspect, it will create a new dummy one that returns nothing, and just assigns a global before returning, then the old function will actually call this dummy function. In short words, this means that this fixer will make calling certain functions (specifically those that have a return value and more than 1 return statements) slightly slower by adding an extra function call.</p>

<p>This method does not work correctly with recursive functions (as it is still not possible to call a function from above its declaration). It is likely that if a function is recursive and has multiple return statements, it will cause a compiler error. In this case, it is better to modify the function, as it is most likely also a return bug false positive (so it probably causes your map to be unplayable in patch 1.24). To prevent this, jasshelper will try to detect the recursion, and if possible, take care of it. But there are some recursion patterns that jasshelper cannot fix at this moment.</p>

<h4 style="color: black">Enabling the return fixer</h4>

<p>This feature must be manually enabled, so if you for some reason need to make your map work specifically with patch 1.24, or if maybe you think that some return bug false positive is still affecting your map, you can enable the feature.</p>

<p>In order to enable the return fixer, take jasshelper.conf and replace [noreturnfixer] with [doreturnfixer] if there is no tag [noreturnfixer] in jasshelper.conf, then simply add the [doreturnfixer] tag to it.</p>

<h3 style="color: black"><a name="import"></a>Import external script files</h3>

<p>JassHelper also includes a //! import preprocessor like WEHelper's, it allows you to import external files.</p>

<p>The usage is //! import "scriptfile" , you can use fixed paths or relative paths.</p>

<p>For 例子 //! import "c:\x.j" will include x.j file located on c:\ in your map script. It is effectively like pasting the file there before compiling it, so the file can include globals, libraries, textmacros, etc. It can even use //! import itself</p>

<p>If you use //! import twice or more on the same file name , the command is ignored.</p>

<p>Relative paths are allowed, for 例子 //! import "x.j" or //! import "subfolder\f.j" will use relative paths. When the path is relative JassHelper will look for the script file in the map's folder or in the lookup folders set in JassHelper's configuration.</p>

<p>Grimoire's version uses jasshelper.conf to determine the lookup folders, WEHelper's version comes with a dialog that allows you to set them. Also the version for WEHelper will automatically add wehelper's import path to the lookup folders list.</p>

<p>WEHelper's internal import preprocessor is most likely to override JassHelper's import since the default is to call it before JassHelper, in case you want to use JassHelper's import you would have to disable WEHelper's, the only advantage the jasshelper one has over the wehelper one is the ability to configure lookup folders.</p>

<p>Grimoire's jassehlper.conf already determines grimoire' Jass folder as a position of scripts. You can add whatever folders you find necessary. Notice that there is a priority system, if a file is found on the map's folder it will be imported no matter the same file exists in another folder used in jasshelper.conf</p>

<p>There is a problem with using the map's folder and it is that testmap saves the map in another path. So you would preffer to use custom paths for this option.</p>

<p>Test map is often problematic with this kind of features. The best way to deal with this is to ALWAYS SAVE BEFORE USING TESTMAP, this will force the map to go to its path and then will use it for testmap, in case you need to test temporary changes, you can save it with another name in the same folder and then do testmap.</p>

<p>As of jasshelper 0.9.C.0 , relative paths used by import an already-imported file will be able to also support the file's path as possible container. Notice that the files in the same folder as the current file have priority over files on the configured paths or even the map's location.</p>

<p>import syntax has been extended to have an extra script type option:</p>

<p>//! import <b>vjass/zinc/comment</b> "filename"</p>

<p>vjass is assumed to be the default. zinc makes the file to be considered a zinc script. comment makes the import command get ignored unless we compile under the warcity mode.</p>

<h3 style="color: black"><a name="zinc"></a>Zinc</h3>

<p>Jasshelper supports two scripting languages, vJass and Zinc. vJass is an extension to wc3's JASS, while Zinc is a less verbose language that is more rigid in certain aspects and also has control structures and things not well compatible with JASS.</p>

<p>For more info on the Zinc language and its syntax please refer to the other file, <a href="zincmanual.html">Zinc manual</a></p>

<h3 style="color: black"><a name="novjass"></a>No vjass!</h3>

<p>The //! novjass and //! endnovjass preprocessor directives allow you to make vjass compilers (like jasshelper) completely ignore the code between them.</p>
<!-- gVim can suck it, jEdit's HTML plugin pwns it in every conceivable way -->

<pre><span class="syntax0"> <span class="syntax-KEYWORD2">function</span> VerifyVJass <span class="syntax-KEYWORD2">takes</span> <span class="syntax-KEYWORD3">nothing</span> <span class="syntax-KEYWORD2">returns</span> <span class="syntax-KEYWORD3">nothing</span>
  <span class="syntax-KEYWORD1">local</span> <span class="syntax-KEYWORD3">boolean</span> b<span class="syntax-OPERATOR">=</span><span class="syntax-LITERAL2">true</span>
    <span class="syntax-COMMENT3">//! novjass</span>
        <span class="syntax-KEYWORD1">set</span> b<span class="syntax-OPERATOR">=</span><span class="syntax-LITERAL2">false</span>
    <span class="syntax-COMMENT3">//! endnovjass</span>
    <span class="syntax-KEYWORD1">if</span><span class="syntax-OPERATOR">(</span>b<span class="syntax-OPERATOR">)</span> <span class="syntax-KEYWORD1">then</span>
        <span class="syntax-KEYWORD1">call</span> <span class="syntax-FUNCTION">BJDebugMsg</span><span class="syntax-OPERATOR">(</span><span class="syntax-LITERAL1">"</span><span class="syntax-LITERAL1">You</span><span class="syntax-LITERAL1"> </span><span class="syntax-LITERAL1">got</span><span class="syntax-LITERAL1"> </span><span class="syntax-LITERAL1">vJass</span><span class="syntax-LITERAL1">"</span><span class="syntax-OPERATOR">)</span>
    <span class="syntax-KEYWORD1">else</span>
        <span class="syntax-KEYWORD1">call</span> <span class="syntax-FUNCTION">BJDebugMsg</span><span class="syntax-OPERATOR">(</span><span class="syntax-LITERAL1">"</span><span class="syntax-LITERAL1">Where</span><span class="syntax-LITERAL1">'</span><span class="syntax-LITERAL1">s</span><span class="syntax-LITERAL1"> </span><span class="syntax-LITERAL1">vJass</span><span class="syntax-LITERAL1">?</span><span class="syntax-LITERAL1">"</span><span class="syntax-OPERATOR">)</span>
    <span class="syntax-KEYWORD1">endif</span>
 <span class="syntax-KEYWORD2">endfunction</span>

</span></pre>

<p>If that code is parsed by a vJass compiler, it will remove what is inside the //! novjass blocks. If the function is just saved in normal World Editor, it will just ignore the //! novjass tags (since it will think they are comments) so it will still consider their contents.</p>

<h3 style="color: black"><a name="lib"></a>Libraries</h3>

<p>Yet another issue with World editor and Jass was that it is impossible to control the order of triggers in the map's script when saved. The custom script partially solved the problem but it is really problematic to ask users to paste things there, it is also anti-modular programming to keep it full of unrelated stuff.</p>

<p>The library preprocessor allows you to keep your top functions in the top and being able to control where each one goes. It also has an smart requirement support so it will sort the function packs for you.</p>

<p>The syntax is simple, you use <b>library</b> LIBRARYNAME or <b>library</b> LIBRARYNAME <b>requires</b> ONEREQUIREMENT or <b>library</b> LIBRARYNAME <b>requires</b> REQ1, REQ2 ...</p>

<p>Remember to mark the end of a library using the <b>endlibrary</b> keyword .</p>

<pre><span class="syntax0"><span class="syntax-KEYWORD2">library</span> B
    <span class="syntax-KEYWORD2">function</span> Bfun <span class="syntax-KEYWORD2">takes</span> <span class="syntax-KEYWORD3">nothing</span> <span class="syntax-KEYWORD2">returns</span> <span class="syntax-KEYWORD3">nothing</span>
    <span class="syntax-KEYWORD2">endfunction</span>
<span class="syntax-KEYWORD2">endlibrary</span>

<span class="syntax-KEYWORD2">library</span> A
    <span class="syntax-KEYWORD2">function</span> Afun <span class="syntax-KEYWORD2">takes</span> <span class="syntax-KEYWORD3">nothing</span> <span class="syntax-KEYWORD2">returns</span> <span class="syntax-KEYWORD3">nothing</span>
    <span class="syntax-KEYWORD2">endfunction</span>
<span class="syntax-KEYWORD2">endlibrary</span>

</span></pre>

<p>If JassHelper finds this command, it will make sure to move the Afun and Bfun functions to the top of the map's script, so the rest of the map's script can freely call Afun() or Bfun().</p>

<p>Notice that it would be uncertain to know what would happen if Afun() was called from a function inside the B library. The command is to move libraries to the top, but we wouldn't know if B went before or after A.</p>

<p>If a function inside library B needed to call a function inside library A we should let JassHelper know that A must be added before B. That's the reason the 'requires' keyword exists:</p>

<pre><span class="syntax0">    <span class="syntax-KEYWORD2">library</span> C <span class="syntax-KEYWORD2">requires</span> A<span class="syntax-OPERATOR">,</span> B<span class="syntax-OPERATOR">,</span> D
        <span class="syntax-KEYWORD2">function</span> Cfun <span class="syntax-KEYWORD2">takes</span> <span class="syntax-KEYWORD3">nothing</span> <span class="syntax-KEYWORD2">returns</span> <span class="syntax-KEYWORD3">nothing</span>
            <span class="syntax-KEYWORD1">call</span> Afun<span class="syntax-OPERATOR">(</span><span class="syntax-OPERATOR">)</span>
            <span class="syntax-KEYWORD1">call</span> Bfun<span class="syntax-OPERATOR">(</span><span class="syntax-OPERATOR">)</span>
            <span class="syntax-KEYWORD1">call</span> Dfun<span class="syntax-OPERATOR">(</span><span class="syntax-OPERATOR">)</span>
        <span class="syntax-KEYWORD2">endfunction</span>
    <span class="syntax-KEYWORD2">endlibrary</span>

    <span class="syntax-KEYWORD2">library</span> D
        <span class="syntax-KEYWORD2">function</span> Dfun <span class="syntax-KEYWORD2">takes</span> <span class="syntax-KEYWORD3">nothing</span> <span class="syntax-KEYWORD2">returns</span> <span class="syntax-KEYWORD3">nothing</span>
        <span class="syntax-KEYWORD2">endfunction</span>
    <span class="syntax-KEYWORD2">endlibrary</span>

    <span class="syntax-KEYWORD2">library</span> B <span class="syntax-KEYWORD2">requires</span> A
        <span class="syntax-KEYWORD2">function</span> Bfun <span class="syntax-KEYWORD2">takes</span> <span class="syntax-KEYWORD3">nothing</span> <span class="syntax-KEYWORD2">returns</span> <span class="syntax-KEYWORD3">nothing</span>
            <span class="syntax-KEYWORD1">call</span> Afun<span class="syntax-OPERATOR">(</span><span class="syntax-OPERATOR">)</span>
        <span class="syntax-KEYWORD2">endfunction</span>
    <span class="syntax-KEYWORD2">endlibrary</span>

    <span class="syntax-KEYWORD2">library</span> A
        <span class="syntax-KEYWORD2">function</span> Afun <span class="syntax-KEYWORD2">takes</span> <span class="syntax-KEYWORD3">nothing</span> <span class="syntax-KEYWORD2">returns</span> <span class="syntax-KEYWORD3">nothing</span>
        <span class="syntax-KEYWORD2">endfunction</span>
    <span class="syntax-KEYWORD2">endlibrary</span>
    
</span></pre>

<p><b>Note: </b> For senseless reasons: <b>requires</b>, <b>needs</b> and <b>uses</b> all work correctly and have the same function in the library syntax, but please use requires, the other ones may be gone one day...</p>

<p>The result in the top of the map would be:</p>

<pre><span class="syntax0">    <span class="syntax-KEYWORD2">function</span> Afun <span class="syntax-KEYWORD2">takes</span> <span class="syntax-KEYWORD3">nothing</span> <span class="syntax-KEYWORD2">returns</span> <span class="syntax-KEYWORD3">nothing</span>
    <span class="syntax-KEYWORD2">endfunction</span>
    <span class="syntax-KEYWORD2">function</span> Dfun <span class="syntax-KEYWORD2">takes</span> <span class="syntax-KEYWORD3">nothing</span> <span class="syntax-KEYWORD2">returns</span> <span class="syntax-KEYWORD3">nothing</span>
    <span class="syntax-KEYWORD2">endfunction</span>
    <span class="syntax-KEYWORD2">function</span> Bfun <span class="syntax-KEYWORD2">takes</span> <span class="syntax-KEYWORD3">nothing</span> <span class="syntax-KEYWORD2">returns</span> <span class="syntax-KEYWORD3">nothing</span>
        <span class="syntax-KEYWORD1">call</span> Afun<span class="syntax-OPERATOR">(</span><span class="syntax-OPERATOR">)</span>
    <span class="syntax-KEYWORD2">endfunction</span>
    <span class="syntax-KEYWORD2">function</span> Cfun <span class="syntax-KEYWORD2">takes</span> <span class="syntax-KEYWORD3">nothing</span> <span class="syntax-KEYWORD2">returns</span> <span class="syntax-KEYWORD3">nothing</span>
        <span class="syntax-KEYWORD1">call</span> Afun<span class="syntax-OPERATOR">(</span><span class="syntax-OPERATOR">)</span>
        <span class="syntax-KEYWORD1">call</span> Bfun<span class="syntax-OPERATOR">(</span><span class="syntax-OPERATOR">)</span>
        <span class="syntax-KEYWORD1">call</span> Dfun<span class="syntax-OPERATOR">(</span><span class="syntax-OPERATOR">)</span>
    <span class="syntax-KEYWORD2">endfunction</span>
    
</span></pre>

<p>Well, not necessarily. It would depend on the order WE saves the scripts in the input file, if two libraries do not require each other, then they may get added on a random order depending on the order in which they are declared in the map. It is always a good idea to require the libraries you are going to use in your library.</p>

<p>Make sure to remember that:</p>

<ul>
	<li>Library names are Case Sensitive.</li>
	<li>If library A requires library B and library B requires library A , there's a cycle and JassHelper will popup a syntax error.</li>
	<li>If library A requires a library that requires B and library B requires A, the cycle is still there.</li>
	<li>You can't nest libraries.</li>
	<li>Libraries might have globals blocks, as of version 0.9.B.0 library requirements determine the order in which these variables are added, notice that this warranty does not exist in prior versions.</li>
</ul>

<p>It is also difficult to control what code is executed first, that's the reason libraries also have an initializer keyword, you can add initializer FUNCTION_NAME after the name of a library and it will make it be executed with priority using ExecuteFunc , ExecuteFunc is forced so it uses another thread, most libraries require heavy operations on init so we better prevent the init thread from crashing. After the initializer keyword the 'needs' statement might be used as well.</p>

<p>The initializers are added to the script in the same order libraries are added. So if library A needs B and both have initializers then B's inititalizer will be called before A's.</p>

<p>Notice the initializer must be a function that takes nothing .</p>

<pre><span class="syntax0">    <span class="syntax-KEYWORD2">library</span> A <span class="syntax-KEYWORD2">initializer</span> InitA <span class="syntax-KEYWORD2">requires</span> B
    
        <span class="syntax-KEYWORD2">function</span> InitA <span class="syntax-KEYWORD2">takes</span> <span class="syntax-KEYWORD3">nothing</span> <span class="syntax-KEYWORD2">returns</span> <span class="syntax-KEYWORD3">nothing</span>
           <span class="syntax-KEYWORD1">call</span> <span class="syntax-KEYWORD4">StoreInteger</span><span class="syntax-OPERATOR">(</span>B_gamecache <span class="syntax-OPERATOR">,</span> <span class="syntax-LITERAL1">"</span><span class="syntax-LITERAL1">a_rect</span><span class="syntax-LITERAL1">"</span> <span class="syntax-OPERATOR">,</span> <span class="syntax-KEYWORD4">Rect</span><span class="syntax-OPERATOR">(</span><span class="syntax-OPERATOR">-</span><span class="syntax-DIGIT">100.0</span> <span class="syntax-OPERATOR">,</span> <span class="syntax-DIGIT">100.0</span> <span class="syntax-OPERATOR">,</span> <span class="syntax-OPERATOR">-</span><span class="syntax-DIGIT">100.0</span> <span class="syntax-OPERATOR">,</span> <span class="syntax-DIGIT">100</span>  <span class="syntax-OPERATOR">)</span> <span class="syntax-OPERATOR">)</span>
        <span class="syntax-KEYWORD2">endfunction</span>
    
    <span class="syntax-KEYWORD2">endlibrary</span>

    <span class="syntax-KEYWORD2">library</span> B <span class="syntax-KEYWORD2">initializer</span> InitB
        <span class="syntax-KEYWORD2">globals</span>
            <span class="syntax-KEYWORD3">gamecache</span> B_gamecache
        <span class="syntax-KEYWORD2">endglobals</span>
    
        <span class="syntax-KEYWORD2">function</span> InitB <span class="syntax-KEYWORD2">takes</span> <span class="syntax-KEYWORD3">nothing</span> <span class="syntax-KEYWORD2">returns</span> <span class="syntax-KEYWORD3">nothing</span>
            <span class="syntax-KEYWORD1">set</span> B_gamecache<span class="syntax-OPERATOR">=</span><span class="syntax-KEYWORD4">InitGameCache</span><span class="syntax-OPERATOR">(</span><span class="syntax-LITERAL1">"</span><span class="syntax-LITERAL1">B</span><span class="syntax-LITERAL1">"</span><span class="syntax-OPERATOR">)</span>
        <span class="syntax-KEYWORD2">endfunction</span>
    <span class="syntax-KEYWORD2">endlibrary</span>

</span></pre>

<p>B's initializer will be called on init before A's initializer.</p>

<p><b>Hints:</b></p>

<ul>
	<li>The <b>library_once</b> keyword works exactly like <b>library</b> but you can declare the same library name twice, it would just ignore the second declaration and avoid to add its contents instead of showing a syntax error, it is useful in combination with textmacros.</li>
	<li>Older versions of vJass had a different syntax for libraries, that started with //! this was eventually deprecated and will now pop a syntax error out.</li>
</ul>

<p></p>

<p><b>Hints:</b> As of 0.9.Z.0, the declaration of a library will create a true boolean constant called LIBRARY_libraryname. Requirements may also be optional (prefix an <b>optional</b> keyword before the requirement name) which means that the library will be moved bellow that requirement, but if the requirement is not found, no syntax error will appear. These may be useful with another new 0.9.Z.0 feature: static ifs.</p>

<h3 style="color: black"><a name="staticif"></a>Static ifs</h3>

<p>static ifs are like normal ifs, except that a) the condition must contain only constant booleans, the <b>and</b> operator and the <b>not</b> operator and b) They are evaluated during compile time. Which means that the code that is not matched to its condition is simply ignored.</p>

<pre><span class="syntax0">    <span class="syntax-KEYWORD2">library</span> OptionalCode <span class="syntax-KEYWORD2">requires</span> <span class="syntax-KEYWORD2">optional</span> UnitKiller
        <span class="syntax-KEYWORD2">globals</span>
            <span class="syntax-KEYWORD2">constant</span> <span class="syntax-KEYWORD3">boolean</span> DO_KILL_LIB <span class="syntax-OPERATOR">=</span> <span class="syntax-LITERAL2">true</span>
        <span class="syntax-KEYWORD2">endglobals</span>

        <span class="syntax-KEYWORD2">function</span> fun <span class="syntax-KEYWORD2">takes</span> <span class="syntax-KEYWORD3">nothing</span> <span class="syntax-KEYWORD2">returns</span> <span class="syntax-KEYWORD3">nothing</span>
            <span class="syntax-KEYWORD1">local</span> <span class="syntax-KEYWORD3">unit</span> u <span class="syntax-OPERATOR">=</span> <span class="syntax-KEYWORD4">GetTriggerUnit</span><span class="syntax-OPERATOR">(</span><span class="syntax-OPERATOR">)</span>
            <span class="syntax-COMMENT2">//</span><span class="syntax-COMMENT2">the</span><span class="syntax-COMMENT2"> </span><span class="syntax-COMMENT2">following</span><span class="syntax-COMMENT2"> </span><span class="syntax-COMMENT2">code</span><span class="syntax-COMMENT2"> </span><span class="syntax-COMMENT2">may</span><span class="syntax-COMMENT2"> </span><span class="syntax-COMMENT2">need</span><span class="syntax-COMMENT2"> </span><span class="syntax-COMMENT2">to</span><span class="syntax-COMMENT2"> </span><span class="syntax-COMMENT2">kill</span><span class="syntax-COMMENT2"> </span><span class="syntax-COMMENT2">the</span><span class="syntax-COMMENT2"> </span><span class="syntax-COMMENT2">unit</span>
            <span class="syntax-COMMENT2">//</span><span class="syntax-COMMENT2">but</span><span class="syntax-COMMENT2"> </span><span class="syntax-COMMENT2">is</span><span class="syntax-COMMENT2"> </span><span class="syntax-COMMENT2">alternatively</span><span class="syntax-COMMENT2"> </span><span class="syntax-COMMENT2">able</span><span class="syntax-COMMENT2"> </span><span class="syntax-COMMENT2">to</span><span class="syntax-COMMENT2"> </span><span class="syntax-COMMENT2">use</span><span class="syntax-COMMENT2"> </span><span class="syntax-COMMENT2">the</span><span class="syntax-COMMENT2"> </span><span class="syntax-COMMENT2">external</span>
            <span class="syntax-COMMENT2">//</span><span class="syntax-COMMENT2">'UnitKiller'</span><span class="syntax-COMMENT2"> </span><span class="syntax-COMMENT2">library</span><span class="syntax-COMMENT2"> </span><span class="syntax-COMMENT2">to</span><span class="syntax-COMMENT2"> </span><span class="syntax-COMMENT2">do</span><span class="syntax-COMMENT2"> </span><span class="syntax-COMMENT2">the</span><span class="syntax-COMMENT2"> </span><span class="syntax-COMMENT2">library.</span>
            <span class="syntax-COMMENT2">//</span><span class="syntax-COMMENT2"> </span><span class="syntax-COMMENT2">ONLY</span><span class="syntax-COMMENT2"> </span><span class="syntax-COMMENT2">when</span><span class="syntax-COMMENT2"> </span><span class="syntax-COMMENT2">DO_KILL_LIB</span><span class="syntax-COMMENT2"> </span><span class="syntax-COMMENT2">is</span><span class="syntax-COMMENT2"> </span><span class="syntax-COMMENT2">true</span><span class="syntax-COMMENT2"> </span><span class="syntax-COMMENT2">AND</span><span class="syntax-COMMENT2"> </span><span class="syntax-COMMENT2">the</span>
            <span class="syntax-COMMENT2">//</span><span class="syntax-COMMENT2"> </span><span class="syntax-COMMENT2">library</span><span class="syntax-COMMENT2"> </span><span class="syntax-COMMENT2">UnitKiller</span><span class="syntax-COMMENT2"> </span><span class="syntax-COMMENT2">is</span><span class="syntax-COMMENT2"> </span><span class="syntax-COMMENT2">in</span><span class="syntax-COMMENT2"> </span><span class="syntax-COMMENT2">the</span><span class="syntax-COMMENT2"> </span><span class="syntax-COMMENT2">map.</span>
            <span class="syntax-KEYWORD2">static</span> <span class="syntax-KEYWORD1">if</span> DO_KILL_LIB <span class="syntax-OPERATOR">and</span> LIBRARY_UnitKiller <span class="syntax-KEYWORD1">then</span>
                <span class="syntax-COMMENT2">//</span><span class="syntax-COMMENT2">static</span><span class="syntax-COMMENT2"> </span><span class="syntax-COMMENT2">if</span><span class="syntax-COMMENT2"> </span><span class="syntax-COMMENT2">because</span><span class="syntax-COMMENT2"> </span><span class="syntax-COMMENT2">if</span><span class="syntax-COMMENT2"> </span><span class="syntax-COMMENT2">the</span><span class="syntax-COMMENT2"> </span><span class="syntax-COMMENT2">UnitKiller</span>
                <span class="syntax-COMMENT2">//</span><span class="syntax-COMMENT2"> </span><span class="syntax-COMMENT2">library</span><span class="syntax-COMMENT2"> </span><span class="syntax-COMMENT2">was</span><span class="syntax-COMMENT2"> </span><span class="syntax-COMMENT2">not</span><span class="syntax-COMMENT2"> </span><span class="syntax-COMMENT2">in</span><span class="syntax-COMMENT2"> </span><span class="syntax-COMMENT2">the</span><span class="syntax-COMMENT2"> </span><span class="syntax-COMMENT2">map,</span><span class="syntax-COMMENT2"> </span><span class="syntax-COMMENT2">using</span><span class="syntax-COMMENT2"> </span><span class="syntax-COMMENT2">a</span><span class="syntax-COMMENT2"> </span><span class="syntax-COMMENT2">normal</span>
                <span class="syntax-COMMENT2">//</span><span class="syntax-COMMENT2"> </span><span class="syntax-COMMENT2">if</span><span class="syntax-COMMENT2"> </span><span class="syntax-COMMENT2">would</span><span class="syntax-COMMENT2"> </span><span class="syntax-COMMENT2">not</span><span class="syntax-COMMENT2"> </span><span class="syntax-COMMENT2">remove</span><span class="syntax-COMMENT2"> </span><span class="syntax-COMMENT2">this</span><span class="syntax-COMMENT2"> </span><span class="syntax-COMMENT2">line</span><span class="syntax-COMMENT2"> </span><span class="syntax-COMMENT2">of</span><span class="syntax-COMMENT2"> </span><span class="syntax-COMMENT2">code</span><span class="syntax-COMMENT2"> </span><span class="syntax-COMMENT2">and</span>
                <span class="syntax-COMMENT2">//</span><span class="syntax-COMMENT2"> </span><span class="syntax-COMMENT2">therefore</span><span class="syntax-COMMENT2"> </span><span class="syntax-COMMENT2">it</span><span class="syntax-COMMENT2"> </span><span class="syntax-COMMENT2">would</span><span class="syntax-COMMENT2"> </span><span class="syntax-COMMENT2">cause</span><span class="syntax-COMMENT2"> </span><span class="syntax-COMMENT2">a</span><span class="syntax-COMMENT2"> </span><span class="syntax-COMMENT2">syntax</span><span class="syntax-COMMENT2"> </span><span class="syntax-COMMENT2">error.</span>
                <span class="syntax-COMMENT2">//</span><span class="syntax-COMMENT2"> </span><span class="syntax-COMMENT2">(unable</span><span class="syntax-COMMENT2"> </span><span class="syntax-COMMENT2">to</span><span class="syntax-COMMENT2"> </span><span class="syntax-COMMENT2">find</span><span class="syntax-COMMENT2"> </span><span class="syntax-COMMENT2">function</span><span class="syntax-COMMENT2"> </span><span class="syntax-COMMENT2">UnitKiller)</span>
                <span class="syntax-KEYWORD1">call</span> UnitKiller<span class="syntax-OPERATOR">(</span>u<span class="syntax-OPERATOR">)</span>
            <span class="syntax-KEYWORD1">else</span>
                <span class="syntax-KEYWORD1">call</span> <span class="syntax-KEYWORD4">KillUnit</span><span class="syntax-OPERATOR">(</span>u<span class="syntax-OPERATOR">)</span>
            <span class="syntax-KEYWORD1">endif</span>
        <span class="syntax-KEYWORD2">endfunction</span>

    <span class="syntax-KEYWORD2">endlibrary</span>

    <span class="syntax-KEYWORD2">library</span> UnitKiller

        <span class="syntax-KEYWORD2">function</span> UnitKiller<span class="syntax-OPERATOR">(</span><span class="syntax-KEYWORD3">unit</span> u<span class="syntax-OPERATOR">)</span>
            <span class="syntax-KEYWORD1">call</span> <span class="syntax-FUNCTION">BJDebugMsg</span><span class="syntax-OPERATOR">(</span><span class="syntax-LITERAL1">"</span><span class="syntax-LITERAL1">Unit</span><span class="syntax-LITERAL1"> </span><span class="syntax-LITERAL1">kill</span><span class="syntax-LITERAL1">!</span><span class="syntax-LITERAL1">"</span><span class="syntax-OPERATOR">)</span>
            <span class="syntax-KEYWORD1">call</span> <span class="syntax-KEYWORD4">KillUnit</span><span class="syntax-OPERATOR">(</span>u<span class="syntax-OPERATOR">)</span>
        <span class="syntax-KEYWORD2">endfunction</span>

    <span class="syntax-KEYWORD2">endfunction</span>

</span></pre>

<h3 style="color: black"><a name="priv"></a>Private members</h3>

<p>With the adition of libraries it was a good idea to add some scope control, private members are a great way of protecting users from themselves and to avoid collisions.</p>

<pre><font color="#000000"><b>library</b></font> <span style="background-color: #ffffff"><font color="#000000">privatetest</font></span>
    <font color="#000000"><b>globals</b></font>
        <font color="#000000"><b>private</b></font> <font color="#7777cc"><b>integer</b></font> <span style="background-color: #ffffff"><font color="#000000">N</font></span>=<font color="#000066">0</font>
    <font color="#000000"><b>endglobals</b></font>
    <font color="#000000"><b>private</b></font> <font color="#000000"><b>function</b></font> <span style="background-color: #ffffff"><font color="#000000">x</font></span> <font color="#000000"><b>takes</b></font> <font color="#7777cc"><b>nothing</b></font> <font color="#000000"><b>returns</b></font> <font color="#7777cc"><b>nothing</b></font>
        <font color="#000000"><b>set</b></font> <span style="background-color: #ffffff"><font color="#000000">N</font></span>=<span style="background-color: #ffffff"><font color="#000000">N</font></span>+<font color="#000066">1</font>
    <font color="#000000"><b>endfunction</b></font>

    <font color="#000000"><b>function</b></font> <span style="background-color: #ffffff"><font color="#000000">privatetest</font></span> <font color="#000000"><b>takes</b></font> <font color="#7777cc"><b>nothing</b></font> <font color="#000000"><b>returns</b></font> <font color="#7777cc"><b>nothing</b></font>
        <font color="#000000"><b>call</b></font> <span style="background-color: #ffffff"><font color="#000000">x</font></span>()
        <font color="#000000"><b>call</b></font> <span style="background-color: #ffffff"><font color="#000000">x</font></span>()
    <font color="#000000"><b>endfunction</b></font>
<font color="#000000"><b>endlibrary</b></font>

<font color="#000000"><b>library</b></font> <span style="background-color: #ffffff"><font color="#000000">otherprivatetest</font></span>
    <font color="#000000"><b>globals</b></font>
        <font color="#000000"><b>private</b></font> <font color="#7777cc"><b>integer</b></font> <span style="background-color: #ffffff"><font color="#000000">N</font></span>=<font color="#000066">5</font>
    <font color="#000000"><b>endglobals</b></font>
    <font color="#000000"><b>private</b></font> <font color="#000000"><b>function</b></font> <span style="background-color: #ffffff"><font color="#000000">x</font></span> <font color="#000000"><b>takes</b></font> <font color="#7777cc"><b>nothing</b></font> <font color="#000000"><b>returns</b></font> <font color="#7777cc"><b>nothing</b></font>
        <font color="#000000"><b>set</b></font> <span style="background-color: #ffffff"><font color="#000000">N</font></span>=<span style="background-color: #ffffff"><font color="#000000">N</font></span>+<font color="#000066">1</font>
    <font color="#000000"><b>endfunction</b></font>

    <font color="#000000"><b>function</b></font> <span style="background-color: #ffffff"><font color="#000000">otherprivatetest</font></span> <font color="#000000"><b>takes</b></font> <font color="#7777cc"><b>nothing</b></font> <font color="#000000"><b>returns</b></font> <font color="#7777cc"><b>nothing</b></font>
        <font color="#000000"><b>call</b></font> <span style="background-color: #ffffff"><font color="#000000">x</font></span>()
        <font color="#000000"><b>call</b></font> <span style="background-color: #ffffff"><font color="#000000">x</font></span>()
    <font color="#000000"><b>endfunction</b></font>
<font color="#000000"><b>endlibrary</b></font>
</pre>

<p>Notice how both libraries have private globals and functions with the same names, this wouldn't cause any syntax errors since the private preprocessor will make sure that private members are only available for that scope and don't conflict with things named the same present in other scopes. In this case private members are only to be used by the libraries in which they are declared.</p>

<p>Sometimes, you don't want the code to go to the top of your script (it is not really a function library) yet you' still want to use the private keyword for a group of globals and functions. This is the reason we defined the <b>scope</b> keyword</p>

<p>The <b>scope</b> keyword has this syntax: <b>scope</b> NAME [...script block...] <b>endscope</b></p>

<p>So, functions and other declarations inside an scope can freely use the private members of the scope, but code outside won't be able to. (Notice that a library is to be considered to have an internal scope with its name)</p>

<p>There are many applications for this feature:</p>

<pre><font color="#000000"><b>scope</b></font> <span style="background-color: #ffffff"><font color="#000000">GetUnitDebugStr</font></span>

    <font color="#000000"><b>private</b></font> <font color="#000000"><b>function</b></font> <span style="background-color: #ffffff"><font color="#000000">H2I</font></span> <font color="#000000"><b>takes</b></font> <font color="#7777cc"><b>handle</b></font> <span style="background-color: #ffffff"><font color="#000000">h</font></span> <font color="#000000"><b>returns</b></font> <font color="#7777cc"><b>integer</b></font>
        <font color="#000000"><b>return</b></font> <span style="background-color: #ffffff"><font color="#000000">h</font></span>
        <font color="#000000"><b>return</b></font> <font color="#000066">0</font>
    <font color="#000000"><b>endfunction</b></font>

    <font color="#000000"><b>function</b></font> <span style="background-color: #ffffff"><font color="#000000">GetUnitDebugStr</font></span> <font color="#000000"><b>takes</b></font> <font color="#7777cc"><b>unit</b></font> <span style="background-color: #ffffff"><font color="#000000">u</font></span> <font color="#000000"><b>returns</b></font> <font color="#7777cc"><b>string</b></font>
        <font color="#000000"><b>return</b></font> <span style="background-color: #ffffff"><font color="#000000">GetUnitName</font></span>(<span style="background-color: #ffffff"><font color="#000000">u</font></span>)+<font color="#0000cc"><i>"_"</i></font>+<span style="background-color: #ffffff"><font color="#000000">I2S</font></span>(<span style="background-color: #ffffff"><font color="#000000">H2I</font></span>(<span style="background-color: #ffffff"><font color="#000000">u</font></span>))
    <font color="#000000"><b>endfunction</b></font>
<font color="#000000"><b>endscope</b></font>
</pre>

<p>In this case, the function uses H2I, but H2I is a very common function name, so there could be conflicts with other scripts that might declare it as well, you could add a whole preffix to the H2I function yourself, or make the function a library that requires another library H2I, but that can be sometimes too complicated, by using an scope and private you can freely use H2I in that function without worrying. It doesn' matter if another H2I is declared elsewhere and it is not a private function, private also makes the scope keep a priority for its members.</p>

<p>It is more important for globals because if you make a function pack you might want to disallow direct access to globals but just allow access to some functions, to keep a sense of encapsullation, for example.</p>

<p>The way private work is actually by automatically prefixing scopename(random digit)__ to the identifier names of the private members. The random digit is a way to let it be truly private so people can not even use them by adding the preffix themselves. A double _ is used because we decided that it is the way to recognize preprocessor-generated variables/functions, so you should avoid to use double __ in your human-declarated identifier names. Being able to recognize preprocessor-generated identifiers is useful when reading the output file (for example when PJass returns syntax errors).</p>

<p>In order to use private members ExecuteFunc or real value change events you have to use SCOPE_PRIVATE (see bellow)</p>

<p><b>Hint:</b>Scopes support <b>initializer</b> just like libraries, there is a difference in implementation and it is that they use a normal call rather than an ExecuteFunc call, if you need a heavy process to init a scope, better use a library initializer or call a subfunction using ExecuteFunc from the scope initializer.</p>

<p><b>Note:</b>In a similar way to libraries, scopes used to have a syntax that required //! , that old syntax is deprecated and will cause a syntax error.</p>

<h3 style="color: black"><a name="pub"></a>Public members</h3>

<p>Public members are closely related to private members in that they do mostly the same, the difference is that public members don't get their names randomized, and can be used outside the scope. For a variable/function declared as public in an scope called SCP you can just use the declared function/variable name inside the scope, but to use it outside of the scope you call it with an SCP_ preffix.</p>

<p>An example should be easier to understand:</p>

<pre>    <font color="#000000"><b>library</b></font> <span style="background-color: #ffffff"><font color="#000000">cookiesystem</font></span>
        <font color="#000000"><b>public</b></font> <font color="#000000"><b>function</b></font> <span style="background-color: #ffffff"><font color="#000000">ko</font></span> <font color="#000000"><b>takes</b></font> <font color="#7777cc"><b>nothing</b></font> <font color="#000000"><b>returns</b></font> <font color="#7777cc"><b>nothing</b></font>
            <font color="#000000"><b>call</b></font> <span style="background-color: #ffffff"><font color="#000000">BJDebugMsg</font></span>(<font color="#0000cc"><i>"a"</i></font>)
        <font color="#000000"><b>endfunction</b></font>

        <font color="#000000"><b>function</b></font> <span style="background-color: #ffffff"><font color="#000000">thisisnotpublicnorprivate</font></span> <font color="#000000"><b>takes</b></font> <font color="#7777cc"><b>nothing</b></font> <font color="#000000"><b>returns</b></font> <font color="#7777cc"><b>nothing</b></font>
             <font color="#000000"><b>call</b></font> <span style="background-color: #ffffff"><font color="#000000">ko</font></span>()
             <font color="#000000"><b>call</b></font> <span style="background-color: #ffffff"><font color="#000000">cookiesystem_ko</font></span>() <font color="#008800">//cookiesystem_ preffix is optional</font>
        <font color="#000000"><b>endfunction</b></font>
    <font color="#000000"><b>endlibrary</b></font>

    <font color="#000000"><b>function</b></font> <span style="background-color: #ffffff"><font color="#000000">outside</font></span> <font color="#000000"><b>takes</b></font> <font color="#7777cc"><b>nothing</b></font> <font color="#000000"><b>returns</b></font> <font color="#7777cc"><b>nothing</b></font>
         <font color="#000000"><b>call</b></font> <span style="background-color: #ffffff"><font color="#000000">cookiesystem_ko</font></span>() <font color="#008800">//cookiesystem_ preffix is required</font>
    <font color="#000000"><b>endfunction</b></font>

</pre>

<p>Public function members can be used by ExecuteFunc or real variable value events, but they always need the scope prefix when used as string:</p>

<pre>    <font color="#000000"><b>library</b></font> <span style="background-color: #ffffff"><font color="#000000">cookiesystem</font></span>
        <font color="#000000"><b>public</b></font> <font color="#000000"><b>function</b></font> <span style="background-color: #ffffff"><font color="#000000">ko</font></span> <font color="#000000"><b>takes</b></font> <font color="#7777cc"><b>nothing</b></font> <font color="#000000"><b>returns</b></font> <font color="#7777cc"><b>nothing</b></font>
            <font color="#000000"><b>call</b></font> <span style="background-color: #ffffff"><font color="#000000">BJDebugMsg</font></span>(<font color="#0000cc"><i>"a"</i></font>)
        <font color="#000000"><b>endfunction</b></font>

        <font color="#000000"><b>function</b></font> <span style="background-color: #ffffff"><font color="#000000">thisisnotpublicnorprivate</font></span> <font color="#000000"><b>takes</b></font> <font color="#7777cc"><b>nothing</b></font> <font color="#000000"><b>returns</b></font> <font color="#7777cc"><b>nothing</b></font>
             <font color="#000000"><b>call</b></font> <span style="background-color: #ffffff"><font color="#000000">ExecuteFunc</font></span>(<font color="#0000cc"><i>"cookiesystem_ko"</i></font>) <font color="#008800">//Needs the prefix no matter it is inside the scope</font>

             <font color="#000000"><b>call</b></font> <span style="background-color: #ffffff"><font color="#000000">ExecuteFunc</font></span>(<font color="#0000cc"><i>"ko"</i></font>) <font color="#008800">//This will most likely crash the game.</font>
             <font color="#000000"><b>call</b></font> <span style="background-color: #ffffff"><font color="#000000">cookiesystem_ko</font></span>() <font color="#008800">//Does not need the prefix but can use it.</font>
             <font color="#000000"><b>call</b></font> <span style="background-color: #ffffff"><font color="#000000">ko</font></span>() <font color="#008800">//since it doesn't need the prefix, the line works correctly.</font>
        <font color="#000000"><b>endfunction</b></font>
    <font color="#000000"><b>endlibrary</b></font>
</pre>

<p>Alternatively, you may use SCOPE_PREFIX (see bellow)</p>

<p>Note: If you use public on a function called InitTrig, it is handled in an special way, instead of becoming ScopeName_InitTrig it will become InitTrig_ScopeName, so you could have an scope/library in a trigger with the same scope name and use this public function instead of manually making InitTrig_Correctname.</p>

<h3 style="color: black"><a name="nests"></a>Nested scopes</h3>

<p>Scopes can be nested, don't confuse this statement with "libraries can be nested", in fact, you cannot even place a <b>library</b> inside an <b>scope</b> definition. You can however, have <b>scope</b> inside either <b>library</b> or <b>scope</b> definitions.</p>

<p>An scope inside another scope is considered a child scope. A child scope is considered to be a public member of the parent scope (?).</p>

<p>A child scope cannot declare members that were previously declared as private or global by a parent scope.</p>

<p>A child scope behaves in relation to its parent in the same way as a normal scope behaves in relation to the whole map script.</p>

<p>Since child scopes are always public members, you can access a child scope' public members froum outside the parent scope, but it needs a prefix for the parent and a prefix for the child.</p>

<p>An example :</p>

<pre>    <font color="#000000"><b>library</b></font> <span style="background-color: #ffffff"><font color="#000000">nestedtest</font></span>
        <font color="#000000"><b>scope</b></font> <span style="background-color: #ffffff"><font color="#000000">A</font></span>
          <font color="#000000"><b>globals</b></font>
            <font color="#000000"><b>private</b></font> <font color="#7777cc"><b>integer</b></font> <span style="background-color: #ffffff"><font color="#000000">N</font></span>=<font color="#000066">4</font>
          <font color="#000000"><b>endglobals</b></font>

          <font color="#000000"><b>public</b></font> <font color="#000000"><b>function</b></font> <span style="background-color: #ffffff"><font color="#000000">display</font></span> <font color="#000000"><b>takes</b></font> <font color="#7777cc"><b>nothing</b></font> <font color="#000000"><b>returns</b></font> <font color="#7777cc"><b>nothing</b></font>
            <font color="#000000"><b>call</b></font> <span style="background-color: #ffffff"><font color="#000000">BJDebugMsg</font></span>(<span style="background-color: #ffffff"><font color="#000000">I2S</font></span>(<span style="background-color: #ffffff"><font color="#000000">N</font></span>))
          <font color="#000000"><b>endfunction</b></font>
        <font color="#000000"><b>endscope</b></font>

        <font color="#000000"><b>scope</b></font> <span style="background-color: #ffffff"><font color="#000000">B</font></span>
            <font color="#000000"><b>globals</b></font>
                <font color="#000000"><b>public</b></font> <font color="#7777cc"><b>integer</b></font> <span style="background-color: #ffffff"><font color="#000000">N</font></span>=<font color="#000066">5</font>
            <font color="#000000"><b>endglobals</b></font>

            <font color="#000000"><b>public</b></font> <font color="#000000"><b>function</b></font> <span style="background-color: #ffffff"><font color="#000000">display</font></span> <font color="#000000"><b>takes</b></font> <font color="#7777cc"><b>nothing</b></font> <font color="#000000"><b>returns</b></font> <font color="#7777cc"><b>nothing</b></font>
                <font color="#000000"><b>call</b></font> <span style="background-color: #ffffff"><font color="#000000">BJDebugMsg</font></span>(<span style="background-color: #ffffff"><font color="#000000">I2S</font></span>(<span style="background-color: #ffffff"><font color="#000000">N</font></span>))
            <font color="#000000"><b>endfunction</b></font>
        <font color="#000000"><b>endscope</b></font>

        <font color="#000000"><b>function</b></font> <span style="background-color: #ffffff"><font color="#000000">nestedDoTest</font></span> <font color="#000000"><b>takes</b></font> <font color="#7777cc"><b>nothing</b></font> <font color="#000000"><b>returns</b></font> <font color="#7777cc"><b>nothing</b></font>
            <font color="#000000"><b>call</b></font> <span style="background-color: #ffffff"><font color="#000000">B_display</font></span>()
            <font color="#000000"><b>call</b></font> <span style="background-color: #ffffff"><font color="#000000">A_display</font></span>()
        <font color="#000000"><b>endfunction</b></font>

    <font color="#000000"><b>endlibrary</b></font>

    <font color="#000000"><b>public</b></font> <font color="#000000"><b>function</b></font> <span style="background-color: #ffffff"><font color="#000000">outside</font></span> <font color="#000000"><b>takes</b></font> <font color="#7777cc"><b>nothing</b></font> <font color="#000000"><b>returns</b></font> <font color="#7777cc"><b>nothing</b></font>
        <font color="#000000"><b>set</b></font> <span style="background-color: #ffffff"><font color="#000000">nestedtest_B_N</font></span>= -<font color="#000066">4</font>
        <font color="#000000"><b>call</b></font> <span style="background-color: #ffffff"><font color="#000000">nestedDoTest</font></span>()
        <font color="#000000"><b>call</b></font> <span style="background-color: #ffffff"><font color="#000000">nestedtest_A_display</font></span>()

    <font color="#000000"><b>endfunction</b></font>

</pre>

<p>The next example will cause a syntax error:</p>

<pre>    <font color="#000000"><b>library</b></font> <span style="background-color: #ffffff"><font color="#000000">nestedtest</font></span>
        <font color="#000000"><b>globals</b></font>
            <font color="#000000"><b>private</b></font> <font color="#7777cc"><b>integer</b></font> <span style="background-color: #ffffff"><font color="#000000">N</font></span>=<font color="#000066">3</font>
        <font color="#000000"><b>endglobals</b></font>

        <font color="#000000"><b>scope</b></font> <span style="background-color: #ffffff"><font color="#000000">A</font></span>
          <font color="#000000"><b>globals</b></font>
            <font color="#000000"><b>private</b></font> <font color="#7777cc"><b>integer</b></font> <span style="background-color: #ffffff"><font color="#000000">N</font></span>=<font color="#000066">4</font> <font color="#008800">//Error: 'N' redeclared</font>
          <font color="#000000"><b>endglobals</b></font>
        <font color="#000000"><b>endscope</b></font>

    <font color="#000000"><b>endlibrary</b></font>

</pre>

<p>It is actually caused by a limitation in the parser, there is a conflict caused by using N for the parent and then declaring it for the child. However this version does not cause syntax errors:</p>

<pre>    <font color="#000000"><b>library</b></font> <span style="background-color: #ffffff"><font color="#000000">nestedtest</font></span>
        <font color="#000000"><b>scope</b></font> <span style="background-color: #ffffff"><font color="#000000">A</font></span>
          <font color="#000000"><b>globals</b></font>
            <font color="#000000"><b>private</b></font> <font color="#7777cc"><b>integer</b></font> <span style="background-color: #ffffff"><font color="#000000">N</font></span>=<font color="#000066">4</font>
          <font color="#000000"><b>endglobals</b></font>
        <font color="#000000"><b>endscope</b></font>

        <font color="#000000"><b>globals</b></font>
            <font color="#000000"><b>private</b></font> <font color="#7777cc"><b>integer</b></font> <span style="background-color: #ffffff"><font color="#000000">N</font></span>=<font color="#000066">3</font>
        <font color="#000000"><b>endglobals</b></font>

    <font color="#000000"><b>endlibrary</b></font>


</pre>

<p>It does kind of the same thing, but since the child's N was declared before the parent's the parser no longer gets in a confusion.</p>

<p>Another thing to keep in mind is that unlike normal global variables, private/public global variables cannot be used before declared, otherwise JassHelper will think they are just normal variables.</p>

<p>Scopes cannot be redeclared, there cannot be 2 scopes with the same name. But 2 child scopes might have the same name if they are children of different scopes, the reason is that they actually don't have the same name, they have different names given by their public child scope situation.</p>

<pre>    <font color="#000000"><b>library</b></font> <span style="background-color: #ffffff"><font color="#000000">nestedtest</font></span>
      <font color="#000000"><b>scope</b></font> <span style="background-color: #ffffff"><font color="#000000">A</font></span>
        <font color="#000000"><b>function</b></font> <span style="background-color: #ffffff"><font color="#000000">kkk</font></span> <font color="#000000"><b>takes</b></font> <font color="#7777cc"><b>nothing</b></font> <font color="#000000"><b>returns</b></font> <font color="#7777cc"><b>nothing</b></font>
            <font color="#000000"><b>set</b></font> <span style="background-color: #ffffff"><font color="#000000">N</font></span>=<span style="background-color: #ffffff"><font color="#000000">N</font></span>+<font color="#000066">5</font>  <font color="#008800">// By the time JassHelper gets to this line, it did not see the private integer N</font>
                       <font color="#008800">// declaration yet, so it assumes N is an attempt to use a global variable and does not</font>
                       <font color="#008800">// do any replacement</font>
        <font color="#000000"><b>endfunction</b></font>
      <font color="#000000"><b>endscope</b></font>

   <font color="#000000"><b>endlibrary</b></font>

   <font color="#000000"><b>scope</b></font> <span style="background-color: #ffffff"><font color="#000000">X</font></span>
       <font color="#000000"><b>scope</b></font> <span style="background-color: #ffffff"><font color="#000000">A</font></span>
          <font color="#008800">//Declaring scope A again does not cause any problem, it is because the scope is actually X_A , the</font>
          <font color="#008800">// previous declaration of A was actually nestedtest_A</font>
          <font color="#000000"><b>function</b></font> <span style="background-color: #ffffff"><font color="#000000">DoSomething</font></span> <font color="#000000"><b>takes</b></font> <font color="#7777cc"><b>nothing</b></font> <font color="#000000"><b>returns</b></font> <font color="#7777cc"><b>nothing</b></font>
          <font color="#000000"><b>endfunction</b></font>

       <font color="#000000"><b>endscope</b></font>
    <font color="#000000"><b>endscope</b></font></pre>

<p>There is no nesting limit, but notice that resulting variable and function names of private/public members get big and bigger depending of the depth of the scope nesting. Bigger variable names may affect performance. Not a lot but they do, and this efficiency issue is to be prevented by an obfuscator/finalizer that renames every identifier in the map script a.k.a the map optimizer's shortest names possible method.</p>

<h4 style="color: black"><a name="sconst"></a>SCOPE_PREFIX and SCOPE_PRIVATE</h4>

<p>Whenever you are inside an scope/library declaration, SCOPE_PREFIX and SCOPE_PRIVATE are enabled string constants that you could use.</p>

<p>SCOPE_PREFIX will return the name (as a Jass string) of the current scope concatenated with an underscode. (The prefix added for public memebers)</p>

<p>SCOPE_PRIVATE will return the name (as a Jass string) of the current prefix for private members.</p>

<pre><font color="#000000"><b>scope</b></font> <span style="background-color: #ffffff"><font color="#000000">test</font></span>

    <font color="#000000"><b>private</b></font> <font color="#000000"><b>function</b></font> <span style="background-color: #ffffff"><font color="#000000">kol</font></span> <font color="#000000"><b>takes</b></font> <font color="#7777cc"><b>nothing</b></font> <font color="#000000"><b>returns</b></font> <font color="#7777cc"><b>nothing</b></font>
        <font color="#000000"><b>call</b></font> <span style="background-color: #ffffff"><font color="#000000">BJDebugMsg</font></span>(<font color="#0000cc"><i>"..."</i></font>)
    <font color="#000000"><b>endfunction</b></font>

    <font color="#000000"><b>function</b></font> <span style="background-color: #ffffff"><font color="#000000">lala</font></span> <font color="#000000"><b>takes</b></font> <font color="#7777cc"><b>nothing</b></font> <font color="#000000"><b>returns</b></font> <font color="#7777cc"><b>nothing</b></font>
         <font color="#000000"><b>call</b></font> <span style="background-color: #ffffff"><font color="#000000">ExecuteFunc</font></span>(<span style="background-color: #ffffff"><font color="#000000">SCOPE_PRIVATE</font></span>+<font color="#0000cc"><i>"kol"</i></font>)
    <font color="#000000"><b>endfunction</b></font>

<font color="#000000"><b>endscope</b></font>

</pre>

<p>In the example, we are allowing lala() to call the private function kol via ExecuteFunc.</p>

<h4 style="color: black"><a name="keyword"></a>keyword</h4>

<p>The keyword statement allows you to declare a replacement directive for an scope without declaring an actual function/variable/etc. It is useful for many reasons, the most important of the reasons being that you cannot use a private/public member in an scope before it is declared, in most cases this limitation is no more than an annoyance requiring you to change the position of declarations, in other situations though this is a limitator of other features.</p>

<p>For example two mutually recursive functions may use .evaluate (keep reading this readme) to call each other, but if you also want the functions to be private it is impossible to do it without using keyword:</p>

<pre><font color="#000000"><b>scope</b></font> <span style="background-color: #ffffff"><font color="#000000">myScope</font></span>

   <font color="#000000"><b>private</b></font> <span style="background-color: #ffffff"><font color="#000000">keyword</font></span> <span style="background-color: #ffffff"><font color="#000000">B</font></span> <font color="#008800">//we were able to declare B as private without having to actually</font>
                     <font color="#008800">//include the statement of the function which would cause conflicts.</font>

   <font color="#000000"><b>private</b></font> <font color="#000000"><b>function</b></font> <span style="background-color: #ffffff"><font color="#000000">A</font></span> <font color="#000000"><b>takes</b></font> <font color="#0055aa"><b>integer</b></font> <span style="background-color: #ffffff"><font color="#000000">i</font></span> <font color="#000000"><b>returns</b></font> <font color="#0055aa"><b>nothing</b></font>
       <font color="#000000"><b>if</b></font>(<span style="background-color: #ffffff"><font color="#000000">i</font></span>!=<font color="#0000aa">0</font>) <font color="#000000"><b>then</b></font>
           <font color="#000000"><b>return</b></font> <span style="background-color: #ffffff"><font color="#000000">B</font></span><font color="#0000aa">.</font><span style="background-color: #ffffff"><font color="#000000">evaluate</font></span>(<span style="background-color: #ffffff"><font color="#000000">i</font></span>-<font color="#0000aa">1</font>)*<font color="#0000aa">2</font> <font color="#008800">//we can safely use B since it was already</font>
                                    <font color="#008800">//declared as a private member of the scope</font>
       <font color="#000000"><b>endif</b></font>
       <font color="#000000"><b>return</b></font> <font color="#0000aa">0</font>
   <font color="#000000"><b>endfunction</b></font>

   <font color="#000000"><b>private</b></font> <font color="#000000"><b>function</b></font> <span style="background-color: #ffffff"><font color="#000000">B</font></span> <font color="#000000"><b>takes</b></font> <font color="#0055aa"><b>integer</b></font> <span style="background-color: #ffffff"><font color="#000000">i</font></span> <font color="#000000"><b>returns</b></font> <font color="#0055aa"><b>nothing</b></font>
       <font color="#000000"><b>if</b></font>(<span style="background-color: #ffffff"><font color="#000000">i</font></span>!=<font color="#0000aa">0</font>) <font color="#000000"><b>then</b></font>
           <font color="#000000"><b>return</b></font> <span style="background-color: #ffffff"><font color="#000000">A</font></span>(<span style="background-color: #ffffff"><font color="#000000">i</font></span>-<font color="#0000aa">1</font>)*<font color="#0000aa">3</font>
       <font color="#000000"><b>endif</b></font>
       <font color="#000000"><b>return</b></font> <font color="#0000aa">0</font>
   <font color="#000000"><b>endfunction</b></font>

<font color="#000000"><b>endscope</b></font>
</pre>

<h3 style="color: black"><a name="textm"></a>Text Macros</h3>

<p>Let's accept it, sometimes we want very complex things added to Jass but other times, the only thing we actually need is an automatic text copy+paste+replace, textmacros were added because they can be really useful in a lot of very different cases</p>

<p>The syntax is simple, //! textmacro NAME [takes argument1, argument2, ..., argument n] then //! endtextmacro to finish. And just a runtextmacro to run. It is easier to understand after an 例子</p>

<pre>    <font color="#666666">//! textmacro Increase takes TYPEWORD</font>
    <font color="#000000"><b>function</b></font> <span style="background-color: #ffffff"><font color="#000000">IncreaseStored</font></span><font color="#666666">$TYPEWORD$</font> <font color="#000000"><b>takes</b></font> <font color="#7777cc"><b>gamecache</b></font> <span style="background-color: #ffffff"><font color="#000000">g</font></span>, <font color="#7777cc"><b>string</b></font> <span style="background-color: #ffffff"><font color="#000000">m</font></span>, <font color="#7777cc"><b>string</b></font> <span style="background-color: #ffffff"><font color="#000000">l</font></span> <font color="#000000"><b>returns</b></font> <font color="#7777cc"><b>nothing</b></font>
        <font color="#000000"><b>call</b></font> <span style="background-color: #ffffff"><font color="#000000">Store</font></span><font color="#666666">$TYPEWORD$</font>(<span style="background-color: #ffffff"><font color="#000000">g</font></span>,<span style="background-color: #ffffff"><font color="#000000">m</font></span>,<span style="background-color: #ffffff"><font color="#000000">l</font></span>,<span style="background-color: #ffffff"><font color="#000000">GetStored</font></span><font color="#666666">$TYPEWORD$</font>(<span style="background-color: #ffffff"><font color="#000000">g</font></span>,<span style="background-color: #ffffff"><font color="#000000">m</font></span>,<span style="background-color: #ffffff"><font color="#000000">l</font></span>)+<font color="#000066">1</font>)
    <font color="#000000"><b>endfunction</b></font>
    <font color="#666666">//! endtextmacro</font>

    <font color="#666666">//! runtextmacro Increase("Integer")</font>
    <font color="#666666">//! runtextmacro Increase("Real")</font></pre>

<p>The result of the example is:</p>

<pre>    <font color="#000000"><b>function</b></font> <span style="background-color: #ffffff"><font color="#000000">IncreaseStoredInteger</font></span> <font color="#000000"><b>takes</b></font> <font color="#7777cc"><b>gamecache</b></font> <span style="background-color: #ffffff"><font color="#000000">g</font></span>, <font color="#7777cc"><b>string</b></font> <span style="background-color: #ffffff"><font color="#000000">m</font></span>, <font color="#7777cc"><b>string</b></font> <span style="background-color: #ffffff"><font color="#000000">l</font></span> <font color="#000000"><b>returns</b></font> <font color="#7777cc"><b>nothing</b></font>
        <font color="#000000"><b>call</b></font> <span style="background-color: #ffffff"><font color="#000000">StoreInteger</font></span>(<span style="background-color: #ffffff"><font color="#000000">g</font></span>,<span style="background-color: #ffffff"><font color="#000000">m</font></span>,<span style="background-color: #ffffff"><font color="#000000">l</font></span>,<span style="background-color: #ffffff"><font color="#000000">GetStoredInteger</font></span>(<span style="background-color: #ffffff"><font color="#000000">g</font></span>,<span style="background-color: #ffffff"><font color="#000000">m</font></span>,<span style="background-color: #ffffff"><font color="#000000">l</font></span>)+<font color="#000066">1</font>)
    <font color="#000000"><b>endfunction</b></font>
    <font color="#000000"><b>function</b></font> <span style="background-color: #ffffff"><font color="#000000">IncreaseStoredReal</font></span> <font color="#000000"><b>takes</b></font> <font color="#7777cc"><b>gamecache</b></font> <span style="background-color: #ffffff"><font color="#000000">g</font></span>, <font color="#7777cc"><b>string</b></font> <span style="background-color: #ffffff"><font color="#000000">m</font></span>, <font color="#7777cc"><b>string</b></font> <span style="background-color: #ffffff"><font color="#000000">l</font></span> <font color="#000000"><b>returns</b></font> <font color="#7777cc"><b>nothing</b></font>
        <font color="#000000"><b>call</b></font> <span style="background-color: #ffffff"><font color="#000000">StoreReal</font></span>(<span style="background-color: #ffffff"><font color="#000000">g</font></span>,<span style="background-color: #ffffff"><font color="#000000">m</font></span>,<span style="background-color: #ffffff"><font color="#000000">l</font></span>,<span style="background-color: #ffffff"><font color="#000000">GetStoredReal</font></span>(<span style="background-color: #ffffff"><font color="#000000">g</font></span>,<span style="background-color: #ffffff"><font color="#000000">m</font></span>,<span style="background-color: #ffffff"><font color="#000000">l</font></span>)+<font color="#000066">1</font>)
    <font color="#000000"><b>endfunction</b></font></pre>

<p>The $$ delimiters are required because the replace tokens could require to be together to other symbols.</p>

<p>Notice that strings and comments are not protected from the text replacement. So if there is a match for any of the arguments delimited by $$ it will always get replaced.</p>

<p>textmacros don't need arguments, in that case you simply remove the takes keyword.</p>

<pre>    <font color="#666666">//! textmacro bye</font>
    <font color="#000000"><b>call</b></font> <span style="background-color: #ffffff"><font color="#000000">BJDebugMsg</font></span>(<font color="#0000cc"><i>"1"</i></font>)
    <font color="#000000"><b>call</b></font> <span style="background-color: #ffffff"><font color="#000000">BJDebugMsg</font></span>(<font color="#0000cc"><i>"2"</i></font>)
    <font color="#000000"><b>call</b></font> <span style="background-color: #ffffff"><font color="#000000">BJDebugMsg</font></span>(<font color="#0000cc"><i>"3"</i></font>)
    <font color="#666666">//! endtextmacro</font>

    <font color="#000000"><b>function</b></font> <span style="background-color: #ffffff"><font color="#000000">test</font></span> <font color="#000000"><b>takes</b></font> <font color="#7777cc"><b>nothing</b></font> <font color="#000000"><b>returns</b></font> <font color="#7777cc"><b>nothing</b></font>
        <font color="#666666">//! runtextmacro bye()</font>
        <font color="#666666">//! runtextmacro bye()</font>
    <font color="#000000"><b>endfunction</b></font></pre>

<p>Textmacros add just a lot of fake dynamism to the language, the next is the typical attach/handle vars call for handles:</p>

<pre>    <font color="#666666">//! textmacro GetSetHandle takes TYPE, TYPENAME</font>
        <font color="#000000"><b>function</b></font> <span style="background-color: #ffffff"><font color="#000000">GetHandle</font></span><font color="#666666">$TYPENAME$</font> <font color="#000000"><b>takes</b></font> <font color="#7777cc"><b>handle</b></font> <span style="background-color: #ffffff"><font color="#000000">h</font></span>, <font color="#7777cc"><b>string</b></font> <span style="background-color: #ffffff"><font color="#000000">k</font></span> <font color="#000000"><b>returns</b></font> <font color="#666666">$TYPE$</font>
            <font color="#000000"><b>return</b></font> <span style="background-color: #ffffff"><font color="#000000">GetStoredInteger</font></span>(<span style="background-color: #ffffff"><font color="#000000">udg_handlevars</font></span>, <span style="background-color: #ffffff"><font color="#000000">I2S</font></span>(<span style="background-color: #ffffff"><font color="#000000">H2I</font></span>(<span style="background-color: #ffffff"><font color="#000000">h</font></span>)), <span style="background-color: #ffffff"><font color="#000000">k</font></span>)
            <font color="#000000"><b>return</b></font> <span style="background-color: #ffffff"><font color="#000000">null</font></span>
        <font color="#000000"><b>endfunction</b></font>
        <font color="#000000"><b>function</b></font> <span style="background-color: #ffffff"><font color="#000000">SetHandle</font></span><font color="#666666">$TYPENAME$</font> <font color="#000000"><b>takes</b></font> <font color="#7777cc"><b>handle</b></font> <span style="background-color: #ffffff"><font color="#000000">h</font></span>, <font color="#7777cc"><b>string</b></font> <span style="background-color: #ffffff"><font color="#000000">k</font></span>, <font color="#666666">$TYPE$</font> <span style="background-color: #ffffff"><font color="#000000">v</font></span> <font color="#000000"><b>returns</b></font> <font color="#7777cc"><b>nothing</b></font>
            <font color="#000000"><b>call</b></font> <span style="background-color: #ffffff"><font color="#000000">StoredInteger</font></span>(<span style="background-color: #ffffff"><font color="#000000">udg_handlevars</font></span>,<span style="background-color: #ffffff"><font color="#000000">I2S</font></span>(<span style="background-color: #ffffff"><font color="#000000">H2I</font></span>(<span style="background-color: #ffffff"><font color="#000000">h</font></span>)),<span style="background-color: #ffffff"><font color="#000000">k</font></span>, <span style="background-color: #ffffff"><font color="#000000">H2I</font></span>(<span style="background-color: #ffffff"><font color="#000000">v</font></span>))
        <font color="#000000"><b>endfunction</b></font>
    <font color="#666666">//! endtextmacro</font>

    <font color="#666666">//! runtextmacro GetSetHandle("unit","Unit")</font>
    <font color="#666666">//! runtextmacro GetSetHandle("location","Loc")</font>
    <font color="#666666">//! runtextmacro GetSetHandle("item","Item")</font></pre>

<p>The development time has beed reduced significantly</p>

<p>Textmacros and scopes/libraries can become best friends by allowing some kind of static object orientedness:</p>

<pre>    <font color="#666666">//! textmacro STACK takes NAME, TYPE, TYPE2STRING</font>
        <font color="#000000"><b>scope</b></font> <font color="#666666">$NAME$</font>
            <font color="#000000"><b>globals</b></font>
                <font color="#000000"><b>private</b></font> <font color="#666666">$TYPE$</font> <font color="#7777cc"><b>array</b></font> <span style="background-color: #ffffff"><font color="#000000">V</font></span>
                <font color="#000000"><b>private</b></font> <font color="#7777cc"><b>integer</b></font> <span style="background-color: #ffffff"><font color="#000000">N</font></span>=<font color="#000066">0</font>
            <font color="#000000"><b>endglobals</b></font>
            <font color="#000000"><b>public</b></font> <font color="#000000"><b>function</b></font> <span style="background-color: #ffffff"><font color="#000000">push</font></span> <font color="#000000"><b>takes</b></font> <font color="#666666">$TYPE$</font> <span style="background-color: #ffffff"><font color="#000000">val</font></span> <font color="#000000"><b>returns</b></font> <font color="#7777cc"><b>nothing</b></font>
                <font color="#000000"><b>set</b></font> <span style="background-color: #ffffff"><font color="#000000">V</font></span>[<span style="background-color: #ffffff"><font color="#000000">N</font></span>]=<span style="background-color: #ffffff"><font color="#000000">val</font></span>
                <font color="#000000"><b>set</b></font> <span style="background-color: #ffffff"><font color="#000000">N</font></span>=<span style="background-color: #ffffff"><font color="#000000">N</font></span>+<font color="#000066">1</font>
            <font color="#000000"><b>endfunction</b></font>

            <font color="#000000"><b>public</b></font> <font color="#000000"><b>function</b></font> <span style="background-color: #ffffff"><font color="#000000">pop</font></span> <font color="#000000"><b>takes</b></font> <font color="#7777cc"><b>nothing</b></font> <font color="#000000"><b>returns</b></font> <font color="#666666">$TYPE$</font>
                <font color="#000000"><b>set</b></font> <span style="background-color: #ffffff"><font color="#000000">N</font></span>=<span style="background-color: #ffffff"><font color="#000000">N</font></span>-<font color="#000066">1</font>
                <font color="#000000"><b>return</b></font> <span style="background-color: #ffffff"><font color="#000000">V</font></span>[<span style="background-color: #ffffff"><font color="#000000">N</font></span>]
            <font color="#000000"><b>endfunction</b></font>

            <font color="#000000"><b>public</b></font> <font color="#000000"><b>function</b></font> <span style="background-color: #ffffff"><font color="#000000">print</font></span> <font color="#000000"><b>takes</b></font> <font color="#7777cc"><b>nothing</b></font> <font color="#000000"><b>returns</b></font> <font color="#7777cc"><b>nothing</b></font>
             <font color="#000000"><b>local</b></font> <font color="#7777cc"><b>integer</b></font> <span style="background-color: #ffffff"><font color="#000000">a</font></span>=<span style="background-color: #ffffff"><font color="#000000">N</font></span>-<font color="#000066">1</font>
                <font color="#000000"><b>call</b></font> <span style="background-color: #ffffff"><font color="#000000">BJDebugMsg</font></span>(<font color="#0000cc"><i>"Contents of $TYPE$ stack $NAME$:"</i></font>)
                <font color="#000000"><b>loop</b></font>
                    <font color="#000000"><b>exitwhen</b></font> <span style="background-color: #ffffff"><font color="#000000">a</font></span>&lt;<font color="#000066">0</font>
                    <font color="#000000"><b>call</b></font> <span style="background-color: #ffffff"><font color="#000000">BJDebugMsg</font></span>(<font color="#0000cc"><i>" "</i></font>+<font color="#666666">$TYPE2STRING$</font>(<span style="background-color: #ffffff"><font color="#000000">V</font></span>[<span style="background-color: #ffffff"><font color="#000000">a</font></span>]))
                    <font color="#000000"><b>set</b></font> <span style="background-color: #ffffff"><font color="#000000">a</font></span>=<span style="background-color: #ffffff"><font color="#000000">a</font></span>-<font color="#000066">1</font>
                <font color="#000000"><b>endloop</b></font>
            <font color="#000000"><b>endfunction</b></font>
        <font color="#000000"><b>endscope</b></font>
    <font color="#666666">//! endtextmacro</font>

    <font color="#666666">//! runtextmacro STACK("StackA","integer","I2S")</font>
    <font color="#666666">//! runtextmacro STACK("StackB","integer","I2S")</font>
    <font color="#666666">//! runtextmacro STACK("StackC","string","")</font>
    <font color="#000000"><b>function</b></font> <span style="background-color: #ffffff"><font color="#000000">Test</font></span> <font color="#000000"><b>takes</b></font> <font color="#7777cc"><b>nothing</b></font> <font color="#000000"><b>returns</b></font> <font color="#7777cc"><b>nothing</b></font>
        <font color="#000000"><b>call</b></font> <span style="background-color: #ffffff"><font color="#000000">StackA_push</font></span>(<font color="#000066">4</font>)
        <font color="#000000"><b>call</b></font> <span style="background-color: #ffffff"><font color="#000000">StackA_push</font></span>(<font color="#000066">5</font>)
        <font color="#000000"><b>call</b></font> <span style="background-color: #ffffff"><font color="#000000">StackB_push</font></span>(<span style="background-color: #ffffff"><font color="#000000">StackA_pop</font></span>())
        <font color="#000000"><b>call</b></font> <span style="background-color: #ffffff"><font color="#000000">StackA_push</font></span>(<font color="#000066">7</font>)
        <font color="#000000"><b>call</b></font> <span style="background-color: #ffffff"><font color="#000000">StackA_print</font></span>()
        <font color="#000000"><b>call</b></font> <span style="background-color: #ffffff"><font color="#000000">StackB_print</font></span>()
        <font color="#000000"><b>call</b></font> <span style="background-color: #ffffff"><font color="#000000">StackC_push</font></span>(<font color="#0000cc"><i>"A"</i></font>)
        <font color="#000000"><b>call</b></font> <span style="background-color: #ffffff"><font color="#000000">StackC_push</font></span>(<font color="#0000cc"><i>"B"</i></font>)
        <font color="#000000"><b>call</b></font> <span style="background-color: #ffffff"><font color="#000000">StackC_push</font></span>(<font color="#0000cc"><i>"C"</i></font>)
        <font color="#000000"><b>call</b></font> <span style="background-color: #ffffff"><font color="#000000">StackC_print</font></span>()
    <font color="#000000"><b>endfunction</b></font>

</pre>

<p><b>Hint:</b> You can use textmacro_once in a similar way to library_once.</p>

<p><b>Hint 2:</b> If you //! runtextmacro optional textmacroname(args), the textmacro line will not cause a syntax error if the textmacro does not exist.</p>

<h3 style="color: black"><a name="stru"></a>Structs</h3>

<p>Structs introduce Jass to the object oriented programming paradigm.</p>

<p>I am unable to explain them without making an example first:</p>

<pre><font color="#000000"><b>struct</b></font> <span style="background-color: #ffffff"><font color="#000000">pair</font></span>
    <font color="#7777cc"><b>integer</b></font> <span style="background-color: #ffffff"><font color="#000000">x</font></span>
    <font color="#7777cc"><b>integer</b></font> <span style="background-color: #ffffff"><font color="#000000">y</font></span>
<font color="#000000"><b>endstruct</b></font>

<font color="#000000"><b>function</b></font> <span style="background-color: #ffffff"><font color="#000000">testpairs</font></span> <font color="#000000"><b>takes</b></font> <font color="#7777cc"><b>nothing</b></font> <font color="#000000"><b>returns</b></font> <font color="#7777cc"><b>nothing</b></font>
 <font color="#000000"><b>local</b></font> <span style="background-color: #ffffff"><font color="#000000">pair</font></span> <span style="background-color: #ffffff"><font color="#000000">A</font></span>=<span style="background-color: #ffffff"><font color="#000000">pair</font></span><font color="#000066">.</font><span style="background-color: #ffffff"><font color="#000000">create</font></span>()
    <font color="#000000"><b>set</b></font> <span style="background-color: #ffffff"><font color="#000000">A</font></span><font color="#000066">.</font><span style="background-color: #ffffff"><font color="#000000">x</font></span>=<font color="#000066">5</font>
    <font color="#000000"><b>set</b></font> <span style="background-color: #ffffff"><font color="#000000">A</font></span><font color="#000066">.</font><span style="background-color: #ffffff"><font color="#000000">x</font></span>=<font color="#000066">8</font>

    <font color="#000000"><b>call</b></font> <span style="background-color: #ffffff"><font color="#000000">BJDebugMsg</font></span>(<span style="background-color: #ffffff"><font color="#000000">I2S</font></span>(<span style="background-color: #ffffff"><font color="#000000">A</font></span><font color="#000066">.</font><span style="background-color: #ffffff"><font color="#000000">x</font></span>)+<font color="#0000cc"><i>" : "</i></font>+<span style="background-color: #ffffff"><font color="#000000">I2S</font></span>(<span style="background-color: #ffffff"><font color="#000000">A</font></span><font color="#000066">.</font><span style="background-color: #ffffff"><font color="#000000">y</font></span>))

    <font color="#000000"><b>call</b></font> <span style="background-color: #ffffff"><font color="#000000">pair</font></span><font color="#000066">.</font><span style="background-color: #ffffff"><font color="#000000">destroy</font></span>(<span style="background-color: #ffffff"><font color="#000000">A</font></span>)

<font color="#000000"><b>endfunction</b></font></pre>

<p>As you can see, you can store multiple values in a single struct, then you can just use the struct as if it was another Jass type, notice the . syntax which is used for members on most common languages.</p>

<h4 style="color: black"><a name="strudecl"></a>Declaring structs</h4>

<p>Before using an struct you need to declare it, duh. The syntax is simply using the struct &lt;name&gt; and endstruct keyword, notice how similar they are to global blocks</p>

<p>To declare a member you simply use &lt;type&gt; &lt;name&gt; [= initial value]</p>

<p>In the above example we are declaring an struct type named pair, which has 2 members: x and y, they do not have an initial value set.</p>

<p>It is usually a good idea to assign initial values to the members, so that you don't have to manually initialize them after creating an object of the struct type, the usual default values are the null ones, but depending on the problem you want to solve you could need any other value.</p>

<h4 style="color: black"><a name="strucrest"></a>Creating and destroying structs</h4>

<p>Structs are pseudo-dynamic, you would often need to create and destroy structs, and you should create an struct an assign it to a variable before using it.</p>

<p>The syntax to <i>create an struct</i> (It is actually to get a unique id) is : structtypename.create()</p>

<p>In the case of the above struct you would have to use pair.create() to get a new struct.</p>

<p>JassHelper is just a preprocessor not a hack so whatever adition to Jass we add is still limited by Jass' own limitations, in this case, structs use arrays which have a 8191 values limit, and we cannot use index 0 which is null for structs, so there is an 8190 instances limit. This limit is for instances of each type, so you may have 8190 objects of a pair struct type and still are able to have many other instances of other types.</p>

<p>It means that if you keep creating many structs of a type without destroying them you would eventually reach the limit. So keep in mind this: IN the case the instances limit of a type is reached structtype.create() WILL RETURN 0.</p>

<p>The limit is not usually a worrying issue, 8190 is in practice a huge number, unless you want to make linked lists or things like that, but those should be solved by a lower level approach.</p>

<p>For example, if you are only using structs for spell instance data, it is even impossible to get more than 9 instances. And many other practical applications would never need more than 2000 instances.</p>

<p>UNLESS, of course some structs that are not used anymore are not getting destroyed. In that case the limit is reached by a bug in the usage of structs that should be fixed (In the case of structs, unlike handles, not destroying them does not increase the memory usage, but the risk of reaching the limit)</p>

<p>If you make calculations, if you create an struct per second and always forget to remove it, the map would need 2 hour, 16 minutes in order to reach the limit.</p>

<p>Either way if you are making this for usage by other people and are unsure about the possibility of reaching the limit you can always use a comparission with 0 after calling create() and block the process somehow in case the error is found.</p>

<p>In case the limit is reached and you don't have a way to catch it, struct 0 would be used and assigned and probably cause some conflicts later, the strenght of the conflicts could be null or huge depending on the way you are using the structs.</p>

<p>If debug mode is on when compiling the script, create() will show a warning message whenever the limit is reached.</p>

<p>To destroy an struct you simply use the destroy method which can work as an instance method or as a class method, in the above example call pair.destroy(a) is used to destroy the instance, but you could also use call a.destroy().</p>

<p>In the case you attempt to destroy the zero struct destroy will do nothing or would show a warning message if debug mode is on.</p>

<h4 style="color: black"><a name="strucuse"></a>Struct usage</h4>

<p>Just declare struct values the way you declare variables/functions/arguments of normal types.</p>

<p>Once an struct is declared and you create it and you want to access it, you have to access its members, the way is often (struct value).(member name) , in the case of pairs you use pair.x to access the x member and pair.y to access the y member.</p>

<p>Once a member is accessed the usage is quite similar to the usage of a variable. You can use it in set statements or as a value inside expressions.</p>

<pre><font color="#000000"><b>struct</b></font> <span style="background-color: #ffffff"><font color="#000000">pair</font></span>
    <font color="#7777cc"><b>integer</b></font> <span style="background-color: #ffffff"><font color="#000000">x</font></span>=<font color="#000066">1</font>
    <font color="#7777cc"><b>integer</b></font> <span style="background-color: #ffffff"><font color="#000000">y</font></span>=<font color="#000066">2</font>
<font color="#000000"><b>endstruct</b></font>

<font color="#000000"><b>function</b></font> <span style="background-color: #ffffff"><font color="#000000">pair_sum</font></span> <font color="#000000"><b>takes</b></font> <span style="background-color: #ffffff"><font color="#000000">pair</font></span> <span style="background-color: #ffffff"><font color="#000000">A</font></span>, <span style="background-color: #ffffff"><font color="#000000">pair</font></span> <span style="background-color: #ffffff"><font color="#000000">B</font></span> <font color="#000000"><b>returns</b></font> <span style="background-color: #ffffff"><font color="#000000">pair</font></span>
 <font color="#000000"><b>local</b></font> <span style="background-color: #ffffff"><font color="#000000">pair</font></span> <span style="background-color: #ffffff"><font color="#000000">C</font></span>=<span style="background-color: #ffffff"><font color="#000000">pair</font></span><font color="#000066">.</font><span style="background-color: #ffffff"><font color="#000000">create</font></span>()
    <font color="#000000"><b>set</b></font> <span style="background-color: #ffffff"><font color="#000000">C</font></span><font color="#000066">.</font><span style="background-color: #ffffff"><font color="#000000">x</font></span>=<span style="background-color: #ffffff"><font color="#000000">A</font></span><font color="#000066">.</font><span style="background-color: #ffffff"><font color="#000000">x</font></span>+<span style="background-color: #ffffff"><font color="#000000">B</font></span><font color="#000066">.</font><span style="background-color: #ffffff"><font color="#000000">x</font></span>
    <font color="#000000"><b>set</b></font> <span style="background-color: #ffffff"><font color="#000000">C</font></span><font color="#000066">.</font><span style="background-color: #ffffff"><font color="#000000">y</font></span>=<span style="background-color: #ffffff"><font color="#000000">A</font></span><font color="#000066">.</font><span style="background-color: #ffffff"><font color="#000000">y</font></span>+<span style="background-color: #ffffff"><font color="#000000">B</font></span><font color="#000066">.</font><span style="background-color: #ffffff"><font color="#000000">y</font></span>
 <font color="#000000"><b>return</b></font> <span style="background-color: #ffffff"><font color="#000000">C</font></span>
<font color="#000000"><b>endfunction</b></font>

<font color="#000000"><b>function</b></font> <span style="background-color: #ffffff"><font color="#000000">testpairs</font></span> <font color="#000000"><b>takes</b></font> <font color="#7777cc"><b>nothing</b></font> <font color="#000000"><b>returns</b></font> <font color="#7777cc"><b>nothing</b></font>
 <font color="#000000"><b>local</b></font> <span style="background-color: #ffffff"><font color="#000000">pair</font></span> <span style="background-color: #ffffff"><font color="#000000">A</font></span>=<span style="background-color: #ffffff"><font color="#000000">pair</font></span><font color="#000066">.</font><span style="background-color: #ffffff"><font color="#000000">create</font></span>()
 <font color="#000000"><b>local</b></font> <span style="background-color: #ffffff"><font color="#000000">pair</font></span> <span style="background-color: #ffffff"><font color="#000000">B</font></span>=<span style="background-color: #ffffff"><font color="#000000">pair_sum</font></span>(<span style="background-color: #ffffff"><font color="#000000">A</font></span>, <span style="background-color: #ffffff"><font color="#000000">A</font></span>)
 <font color="#000000"><b>local</b></font> <span style="background-color: #ffffff"><font color="#000000">pair</font></span> <span style="background-color: #ffffff"><font color="#000000">C</font></span>=<span style="background-color: #ffffff"><font color="#000000">pair_sum</font></span>(<span style="background-color: #ffffff"><font color="#000000">A</font></span>,<span style="background-color: #ffffff"><font color="#000000">B</font></span>)

    <font color="#000000"><b>call</b></font> <span style="background-color: #ffffff"><font color="#000000">BJDebugMsg</font></span>(<span style="background-color: #ffffff"><font color="#000000">I2S</font></span>(<span style="background-color: #ffffff"><font color="#000000">C</font></span><font color="#000066">.</font><span style="background-color: #ffffff"><font color="#000000">x</font></span>)+<font color="#0000cc"><i>" : "</i></font>+<span style="background-color: #ffffff"><font color="#000000">I2S</font></span>(<span style="background-color: #ffffff"><font color="#000000">C</font></span><font color="#000066">.</font><span style="background-color: #ffffff"><font color="#000000">y</font></span>))

    <font color="#008800">//Dont forget, if you are not using an struct instance anymore, you destroy it</font>
    <font color="#000000"><b>call</b></font> <span style="background-color: #ffffff"><font color="#000000">B</font></span><font color="#000066">.</font><span style="background-color: #ffffff"><font color="#000000">destroy</font></span>()
    <font color="#000000"><b>call</b></font> <span style="background-color: #ffffff"><font color="#000000">C</font></span><font color="#000066">.</font><span style="background-color: #ffffff"><font color="#000000">destroy</font></span>()
    <font color="#000000"><b>call</b></font> <span style="background-color: #ffffff"><font color="#000000">pair</font></span><font color="#000066">.</font><span style="background-color: #ffffff"><font color="#000000">destroy</font></span>(<span style="background-color: #ffffff"><font color="#000000">A</font></span>)

<font color="#000000"><b>endfunction</b></font></pre>

<p>It would display "3 : 6"</p>

<h4 style="color: black"><a name="strucins"></a>Instance members</h4>

<p>So, you can declare struct members of any type, even struct types. You cannot however declare array members, this limitation should be removed in later versions.</p>

<pre><font color="#000000"><b>struct</b></font> <span style="background-color: #ffffff"><font color="#000000">pairpair</font></span>
    <span style="background-color: #ffffff"><font color="#000000">pair</font></span> <span style="background-color: #ffffff"><font color="#000000">x</font></span>=<font color="#000066">0</font> <font color="#008800">//you cannot use pair.create() and should actually only use constants for default initial values.</font>
    <span style="background-color: #ffffff"><font color="#000000">pair</font></span> <span style="background-color: #ffffff"><font color="#000000">y</font></span>=<font color="#000066">0</font>
<font color="#000000"><b>endstruct</b></font>

<font color="#000000"><b>function</b></font> <span style="background-color: #ffffff"><font color="#000000">testpairs</font></span> <font color="#000000"><b>takes</b></font> <font color="#7777cc"><b>nothing</b></font> <font color="#000000"><b>returns</b></font> <font color="#7777cc"><b>nothing</b></font>
 <font color="#000000"><b>local</b></font> <span style="background-color: #ffffff"><font color="#000000">pairpair</font></span> <span style="background-color: #ffffff"><font color="#000000">A</font></span>=<span style="background-color: #ffffff"><font color="#000000">pairpair</font></span><font color="#000066">.</font><span style="background-color: #ffffff"><font color="#000000">create</font></span>()
 <font color="#000000"><b>local</b></font> <span style="background-color: #ffffff"><font color="#000000">pair</font></span> <span style="background-color: #ffffff"><font color="#000000">x</font></span>

    <font color="#000000"><b>set</b></font> <span style="background-color: #ffffff"><font color="#000000">A</font></span><font color="#000066">.</font><span style="background-color: #ffffff"><font color="#000000">x</font></span>=<span style="background-color: #ffffff"><font color="#000000">pair</font></span><font color="#000066">.</font><span style="background-color: #ffffff"><font color="#000000">create</font></span>()
    <font color="#000000"><b>set</b></font> <span style="background-color: #ffffff"><font color="#000000">A</font></span><font color="#000066">.</font><span style="background-color: #ffffff"><font color="#000000">y</font></span>=<span style="background-color: #ffffff"><font color="#000000">pair</font></span><font color="#000066">.</font><span style="background-color: #ffffff"><font color="#000000">create</font></span>()

    <font color="#000000"><b>set</b></font> <span style="background-color: #ffffff"><font color="#000000">x</font></span>=<span style="background-color: #ffffff"><font color="#000000">A</font></span><font color="#000066">.</font><span style="background-color: #ffffff"><font color="#000000">y</font></span> <font color="#008800">//notice we are saving A.y in a backup variable so we can destroy it.</font>
    <font color="#000000"><b>set</b></font> <span style="background-color: #ffffff"><font color="#000000">A</font></span><font color="#000066">.</font><span style="background-color: #ffffff"><font color="#000000">y</font></span>= <span style="background-color: #ffffff"><font color="#000000">pair_sum</font></span>(<span style="background-color: #ffffff"><font color="#000000">A</font></span><font color="#000066">.</font><span style="background-color: #ffffff"><font color="#000000">x</font></span>,<span style="background-color: #ffffff"><font color="#000000">A</font></span><font color="#000066">.</font><span style="background-color: #ffffff"><font color="#000000">y</font></span>) <font color="#008800">//this replaces A.y that's the reason we saved it</font>

    <font color="#000000"><b>call</b></font> <span style="background-color: #ffffff"><font color="#000000">BJDebugMsg</font></span>(<span style="background-color: #ffffff"><font color="#000000">I2S</font></span>(  <span style="background-color: #ffffff"><font color="#000000">A</font></span><font color="#000066">.</font><span style="background-color: #ffffff"><font color="#000000">y</font></span><font color="#000066">.</font><span style="background-color: #ffffff"><font color="#000000">x</font></span> )+<font color="#0000cc"><i>" : "</i></font>+<span style="background-color: #ffffff"><font color="#000000">I2S</font></span>( <span style="background-color: #ffffff"><font color="#000000">A</font></span><font color="#000066">.</font><span style="background-color: #ffffff"><font color="#000000">y</font></span><font color="#000066">.</font><span style="background-color: #ffffff"><font color="#000000">y</font></span> )) <font color="#008800">//notice the nesting of the . operator</font>

    <font color="#000000"><b>call</b></font> <span style="background-color: #ffffff"><font color="#000000">A</font></span><font color="#000066">.</font><span style="background-color: #ffffff"><font color="#000000">x</font></span><font color="#000066">.</font><span style="background-color: #ffffff"><font color="#000000">destroy</font></span>()
    <font color="#000000"><b>call</b></font> <span style="background-color: #ffffff"><font color="#000000">A</font></span><font color="#000066">.</font><span style="background-color: #ffffff"><font color="#000000">y</font></span><font color="#000066">.</font><span style="background-color: #ffffff"><font color="#000000">destroy</font></span>()
    <font color="#000000"><b>call</b></font> <span style="background-color: #ffffff"><font color="#000000">A</font></span><font color="#000066">.</font><span style="background-color: #ffffff"><font color="#000000">destroy</font></span>()
    <font color="#000000"><b>call</b></font> <span style="background-color: #ffffff"><font color="#000000">x</font></span><font color="#000066">.</font><span style="background-color: #ffffff"><font color="#000000">destroy</font></span>()
<font color="#000000"><b>endfunction</b></font></pre>

<h4 style="color: black"><a name="strucglob"></a>Globals of struct types</h4>

<p>You can have globals of struct types. Because of Jass' limitations you cannot initialize them directly.</p>

<pre><font color="#000000"><b>globals</b></font>
     <span style="background-color: #ffffff"><font color="#000000">pair</font></span> <span style="background-color: #ffffff"><font color="#000000">globalpair</font></span>=<font color="#000066">0</font> <font color="#008800">//legal</font>
     <span style="background-color: #ffffff"><font color="#000000">pair</font></span> <span style="background-color: #ffffff"><font color="#000000">globalpair2</font></span>= <span style="background-color: #ffffff"><font color="#000000">pair</font></span><font color="#000066">.</font><span style="background-color: #ffffff"><font color="#000000">create</font></span>() <font color="#008800">//not legal</font>
<font color="#000000"><b>endglobals</b></font></pre>

<p>You would have to assign them in an init function instead.</p>

<h4 style="color: black"><a name="strucstat"></a>Static members</h4>

<p>An static member would just behave like a global variable inside struct syntax, just add the static keyword before the member syntax. There can be static arrays as well.</p>

<p>They might be useful in conjunction to methods.</p>

<h4 style="color: black"><a name="strucpubriv"></a>public/private Structs</h4>

<p>You can declare scope's public or private structs and struct variables with all freedom</p>

<pre><font color="#000000"><b>scope</b></font> <span style="background-color: #ffffff"><font color="#000000">cool</font></span>
    <font color="#000000"><b>public</b></font> <font color="#000000"><b>struct</b></font> <span style="background-color: #ffffff"><font color="#000000">a</font></span>
        <font color="#7777cc"><b>integer</b></font> <span style="background-color: #ffffff"><font color="#000000">x</font></span>
    <font color="#000000"><b>endstruct</b></font>

    <font color="#000000"><b>globals</b></font>
        <span style="background-color: #ffffff"><font color="#000000">a</font></span> <span style="background-color: #ffffff"><font color="#000000">x</font></span>
        <font color="#000000"><b>public</b></font> <span style="background-color: #ffffff"><font color="#000000">a</font></span> <span style="background-color: #ffffff"><font color="#000000">b</font></span>
    <font color="#000000"><b>endglobals</b></font>


    <font color="#000000"><b>public</b></font> <font color="#000000"><b>function</b></font> <span style="background-color: #ffffff"><font color="#000000">test</font></span> <font color="#000000"><b>takes</b></font> <font color="#7777cc"><b>nothing</b></font> <font color="#000000"><b>returns</b></font> <font color="#7777cc"><b>nothing</b></font>
        <font color="#000000"><b>set</b></font> <span style="background-color: #ffffff"><font color="#000000">b</font></span> = <span style="background-color: #ffffff"><font color="#000000">a</font></span><font color="#000066">.</font><span style="background-color: #ffffff"><font color="#000000">create</font></span>()
        <font color="#000000"><b>set</b></font> <span style="background-color: #ffffff"><font color="#000000">b</font></span><font color="#000066">.</font><span style="background-color: #ffffff"><font color="#000000">x</font></span> = <font color="#000066">3</font>
        <font color="#000000"><b>call</b></font> <span style="background-color: #ffffff"><font color="#000000">b</font></span><font color="#000066">.</font><span style="background-color: #ffffff"><font color="#000000">destroy</font></span>()
    <font color="#000000"><b>endfunction</b></font>

<font color="#000000"><b>endscope</b></font>

<font color="#000000"><b>function</b></font> <span style="background-color: #ffffff"><font color="#000000">test</font></span> <font color="#000000"><b>takes</b></font> <font color="#7777cc"><b>nothing</b></font> <font color="#000000"><b>returns</b></font> <font color="#7777cc"><b>nothing</b></font>
 <font color="#000000"><b>local</b></font> <span style="background-color: #ffffff"><font color="#000000">cool_a</font></span> <span style="background-color: #ffffff"><font color="#000000">x</font></span>=<span style="background-color: #ffffff"><font color="#000000">cool_a</font></span><font color="#000066">.</font><span style="background-color: #ffffff"><font color="#000000">create</font></span>()
    <font color="#000000"><b>set</b></font> <span style="background-color: #ffffff"><font color="#000000">a</font></span><font color="#000066">.</font><span style="background-color: #ffffff"><font color="#000000">x</font></span>=<font color="#000066">6</font>
    <font color="#000000"><b>call</b></font> <span style="background-color: #ffffff"><font color="#000000">a</font></span><font color="#000066">.</font><span style="background-color: #ffffff"><font color="#000000">destroy</font></span>()
<font color="#000000"><b>endfunction</b></font>
</pre>

<h4 style="color: black"><a name="strucmeth"></a>Methods</h4>

<p>Methods are just like functions, the difference is that they are associated with the class, also [normal] methods are associated with an instance (in this case 'this')</p>

<p>Once again an example is needed</p>

<pre>    <font color="#000000"><b>struct</b></font> <span style="background-color: #ffffff"><font color="#000000">point</font></span>
        <font color="#7777cc"><b>real</b></font> <span style="background-color: #ffffff"><font color="#000000">x</font></span><font color="#000066">=0.0</font>
        <font color="#7777cc"><b>real</b></font> <span style="background-color: #ffffff"><font color="#000000">y</font></span><font color="#000066">=0.0</font>

        <font color="#000000"><b>method</b></font> <span style="background-color: #ffffff"><font color="#000000">move</font></span> <font color="#000000"><b>takes</b></font> <font color="#7777cc"><b>real</b></font> <span style="background-color: #ffffff"><font color="#000000">tx</font></span>, <font color="#7777cc"><b>real</b></font> <span style="background-color: #ffffff"><font color="#000000">ty</font></span> <font color="#000000"><b>returns</b></font> <font color="#7777cc"><b>nothing</b></font>
            <font color="#000000"><b>set</b></font> <font color="#000066">this</font><font color="#000066">.</font><span style="background-color: #ffffff"><font color="#000000">x</font></span>=<span style="background-color: #ffffff"><font color="#000000">tx</font></span>
            <font color="#000000"><b>set</b></font> <font color="#000066">this</font><font color="#000066">.</font><span style="background-color: #ffffff"><font color="#000000">y</font></span>=<span style="background-color: #ffffff"><font color="#000000">ty</font></span>
        <font color="#000000"><b>endmethod</b></font>

    <font color="#000000"><b>endstruct</b></font>

    <font color="#000000"><b>function</b></font> <span style="background-color: #ffffff"><font color="#000000">testpoint</font></span> <font color="#000000"><b>takes</b></font> <font color="#7777cc"><b>nothing</b></font> <font color="#000000"><b>returns</b></font> <font color="#7777cc"><b>nothing</b></font>
     <font color="#000000"><b>local</b></font> <span style="background-color: #ffffff"><font color="#000000">point</font></span> <span style="background-color: #ffffff"><font color="#000000">p</font></span>=<span style="background-color: #ffffff"><font color="#000000">point</font></span><font color="#000066">.</font><span style="background-color: #ffffff"><font color="#000000">create</font></span>()
        <font color="#000000"><b>call</b></font> <span style="background-color: #ffffff"><font color="#000000">p</font></span><font color="#000066">.</font><span style="background-color: #ffffff"><font color="#000000">move</font></span>(<font color="#000066">56</font>,<font color="#000066">89</font>)

        <font color="#000000"><b>call</b></font> <span style="background-color: #ffffff"><font color="#000000">BJDebugMsg</font></span>(<span style="background-color: #ffffff"><font color="#000000">R2S</font></span>(<span style="background-color: #ffffff"><font color="#000000">p</font></span><font color="#000066">.</font><span style="background-color: #ffffff"><font color="#000000">x</font></span>))
    <font color="#000000"><b>endfunction</b></font>
</pre>

<p><b>this</b> : A keyword that denotes a pointer to current instance, [normal] methods are instance methods which means that they are called from an already assigned variable/value of that type, and this will point to it. In the above example we use this inside the method to assign x and y, when calling p.move() it ends up modiffying x and y attributes for the struct pointed by p.</p>

<p><b>method syntax</b> : You might notice that method syntax is really similar to function syntax.</p>

<p><b>this is optional</b> : You can use a single . instead of this. when you are inside an instance method. (For example set .member = value)</p>

<p>Methods are different to normal functions in that they can be called from any place (except global declarations) and that you are not necessarily able to use waits, sync natives or GetTriggeringTrigger() inside them (but you may use any other event response), you might be able to use them but it depends on various factors, it is not recommended to use them at all. In next versions the compiler might even raise a syntax error when it finds them.</p>

<h4 style="color: black"><a name="strucenc"></a>Encapsullation</h4>

<p>Encapsullation is an object oriented programming concept in which you only give access to things that need to have access, in other words it is private and public for structs</p>

<pre>    <font color="#000000"><b>struct</b></font> <span style="background-color: #ffffff"><font color="#000000">encap</font></span>
        <font color="#7777cc"><b>real</b></font> <span style="background-color: #ffffff"><font color="#000000">a</font></span><font color="#000066">=0.0</font>
        <font color="#000000"><b>private</b></font> <font color="#7777cc"><b>real</b></font> <span style="background-color: #ffffff"><font color="#000000">b</font></span><font color="#000066">=0.0</font>
        <font color="#000000"><b>public</b></font> <font color="#7777cc"><b>real</b></font> <span style="background-color: #ffffff"><font color="#000000">c</font></span><font color="#000066">=4.5</font>

        <font color="#000000"><b>method</b></font> <span style="background-color: #ffffff"><font color="#000000">randomize</font></span> <font color="#000000"><b>takes</b></font> <font color="#7777cc"><b>nothing</b></font> <font color="#000000"><b>returns</b></font> <font color="#7777cc"><b>nothing</b></font>
            <font color="#008800">// All legal:</font>
            <font color="#000000"><b>set</b></font> <font color="#000066">this</font><font color="#000066">.</font><span style="background-color: #ffffff"><font color="#000000">a</font></span>= <span style="background-color: #ffffff"><font color="#000000">GetRandomReal</font></span>(<font color="#000066">0</font>,<font color="#000066">45.0</font>)
            <font color="#000000"><b>set</b></font> <font color="#000066">this</font><font color="#000066">.</font><span style="background-color: #ffffff"><font color="#000000">b</font></span>= <span style="background-color: #ffffff"><font color="#000000">GetRandomReal</font></span>(<font color="#000066">0</font>,<font color="#000066">45.0</font>)
            <font color="#000000"><b>set</b></font> <font color="#000066">this</font><font color="#000066">.</font><span style="background-color: #ffffff"><font color="#000000">c</font></span>= <span style="background-color: #ffffff"><font color="#000000">GetRandomReal</font></span>(<font color="#000066">0</font>,<font color="#000066">45.0</font>)
        <font color="#000000"><b>endmethod</b></font>

    <font color="#000000"><b>endstruct</b></font>

    <font color="#000000"><b>function</b></font> <span style="background-color: #ffffff"><font color="#000000">test</font></span> <font color="#000000"><b>takes</b></font> <font color="#7777cc"><b>nothing</b></font> <font color="#000000"><b>returns</b></font> <font color="#7777cc"><b>nothing</b></font>
     <font color="#000000"><b>local</b></font> <span style="background-color: #ffffff"><font color="#000000">encap</font></span> <span style="background-color: #ffffff"><font color="#000000">e</font></span>=<span style="background-color: #ffffff"><font color="#000000">encap</font></span><font color="#000066">.</font><span style="background-color: #ffffff"><font color="#000000">create</font></span>()

         <font color="#000000"><b>call</b></font> <span style="background-color: #ffffff"><font color="#000000">BJDebugMsg</font></span>(<span style="background-color: #ffffff"><font color="#000000">R2S</font></span>(<span style="background-color: #ffffff"><font color="#000000">e</font></span><font color="#000066">.</font><span style="background-color: #ffffff"><font color="#000000">a</font></span>)) <font color="#008800">//legal</font>
         <font color="#000000"><b>call</b></font> <span style="background-color: #ffffff"><font color="#000000">BJDebugMsg</font></span>(<span style="background-color: #ffffff"><font color="#000000">R2S</font></span>(<span style="background-color: #ffffff"><font color="#000000">e</font></span><font color="#000066">.</font><span style="background-color: #ffffff"><font color="#000000">c</font></span>)) <font color="#008800">//legal</font>
         <font color="#000000"><b>call</b></font> <span style="background-color: #ffffff"><font color="#000000">BJDebugMsg</font></span>(<span style="background-color: #ffffff"><font color="#000000">R2S</font></span>(<span style="background-color: #ffffff"><font color="#000000">e</font></span><font color="#000066">.</font><span style="background-color: #ffffff"><font color="#000000">b</font></span>)) <font color="#008800">//syntax error</font>

    <font color="#000000"><b>endfunction</b></font>
</pre>

<p>private members can only be used inside the struct declaration. Public and private are options for both variables and methods.</p>

<p>All struct members are public by default, so the public keyword is not necessary, on the other hand you must specify private. Something to point out is the existance of the readonly keyword, it allows code outside the struct to read the variable but not to assign it. It is a nonstandard at the moment, so you shouldn't use it on public releases.</p>

<h4 style="color: black"><a name="strucmethstac"></a>Static methods</h4>

<p>Static methods or class methods do not use an instance, they are actually like functions but since they are declared inside the struct they can use private members.</p>

<pre>    <font color="#000000"><b>struct</b></font> <span style="background-color: #ffffff"><font color="#000000">encap</font></span>
        <font color="#7777cc"><b>real</b></font> <span style="background-color: #ffffff"><font color="#000000">a</font></span><font color="#000066">=0.0</font>
        <font color="#000000"><b>private</b></font> <font color="#7777cc"><b>real</b></font> <span style="background-color: #ffffff"><font color="#000000">b</font></span><font color="#000066">=0.0</font>
        <font color="#000000"><b>public</b></font> <font color="#7777cc"><b>real</b></font> <span style="background-color: #ffffff"><font color="#000000">c</font></span><font color="#000066">=4.5</font>

        <font color="#000000"><b>private</b></font> <font color="#000000"><b>method</b></font> <span style="background-color: #ffffff"><font color="#000000">dosomething</font></span> <font color="#000000"><b>takes</b></font> <font color="#7777cc"><b>nothing</b></font> <font color="#000000"><b>returns</b></font> <font color="#7777cc"><b>nothing</b></font>
            <font color="#000000"><b>if</b></font> (<font color="#000066">this</font><font color="#000066">.</font><span style="background-color: #ffffff"><font color="#000000">a</font></span>==<font color="#000066">5</font>) <font color="#000000"><b>then</b></font>
                <font color="#000000"><b>set</b></font> <font color="#000066">this</font><font color="#000066">.</font><span style="background-color: #ffffff"><font color="#000000">a</font></span>=<font color="#000066">56</font>
            <font color="#000000"><b>endif</b></font>
        <font color="#000000"><b>endmethod</b></font>

        <font color="#000000"><b>static</b></font> <font color="#000000"><b>method</b></font> <span style="background-color: #ffffff"><font color="#000000">altcreate</font></span> <font color="#000000"><b>takes</b></font> <font color="#7777cc"><b>real</b></font> <span style="background-color: #ffffff"><font color="#000000">a</font></span>, <font color="#7777cc"><b>real</b></font> <span style="background-color: #ffffff"><font color="#000000">b</font></span>, <font color="#7777cc"><b>real</b></font> <span style="background-color: #ffffff"><font color="#000000">c</font></span> <font color="#000000"><b>returns</b></font> <span style="background-color: #ffffff"><font color="#000000">encap</font></span>
         <font color="#000000"><b>local</b></font> <span style="background-color: #ffffff"><font color="#000000">encap</font></span> <span style="background-color: #ffffff"><font color="#000000">r</font></span>=<span style="background-color: #ffffff"><font color="#000000">encap</font></span><font color="#000066">.</font><span style="background-color: #ffffff"><font color="#000000">create</font></span>()
            <font color="#000000"><b>set</b></font> <span style="background-color: #ffffff"><font color="#000000">r</font></span><font color="#000066">.</font><span style="background-color: #ffffff"><font color="#000000">a</font></span>=<span style="background-color: #ffffff"><font color="#000000">a</font></span>
            <font color="#000000"><b>set</b></font> <span style="background-color: #ffffff"><font color="#000000">r</font></span><font color="#000066">.</font><span style="background-color: #ffffff"><font color="#000000">b</font></span>=<span style="background-color: #ffffff"><font color="#000000">b</font></span>
            <font color="#000000"><b>set</b></font> <span style="background-color: #ffffff"><font color="#000000">r</font></span><font color="#000066">.</font><span style="background-color: #ffffff"><font color="#000000">c</font></span>=<span style="background-color: #ffffff"><font color="#000000">c</font></span>
            <font color="#000000"><b>call</b></font> <span style="background-color: #ffffff"><font color="#000000">r</font></span><font color="#000066">.</font><span style="background-color: #ffffff"><font color="#000000">dosomething</font></span>() <font color="#008800">//even though it is private you can use</font>
                                 <font color="#008800">//it since we are inside the struct declaration</font>
         <font color="#000000"><b>return</b></font> <span style="background-color: #ffffff"><font color="#000000">r</font></span>
        <font color="#000000"><b>endmethod</b></font>

        <font color="#000000"><b>method</b></font> <span style="background-color: #ffffff"><font color="#000000">randomize</font></span> <font color="#000000"><b>takes</b></font> <font color="#7777cc"><b>nothing</b></font> <font color="#000000"><b>returns</b></font> <font color="#7777cc"><b>nothing</b></font>
            <font color="#008800">// All legal:</font>
            <font color="#000000"><b>set</b></font> <font color="#000066">this</font><font color="#000066">.</font><span style="background-color: #ffffff"><font color="#000000">a</font></span>= <span style="background-color: #ffffff"><font color="#000000">GetRandomReal</font></span>(<font color="#000066">0</font>,<font color="#000066">45.0</font>)
            <font color="#000000"><b>set</b></font> <font color="#000066">this</font><font color="#000066">.</font><span style="background-color: #ffffff"><font color="#000000">b</font></span>= <span style="background-color: #ffffff"><font color="#000000">GetRandomReal</font></span>(<font color="#000066">0</font>,<font color="#000066">45.0</font>)
            <font color="#000000"><b>set</b></font> <font color="#000066">this</font><font color="#000066">.</font><span style="background-color: #ffffff"><font color="#000000">c</font></span>= <span style="background-color: #ffffff"><font color="#000000">GetRandomReal</font></span>(<font color="#000066">0</font>,<font color="#000066">45.0</font>)
        <font color="#000000"><b>endmethod</b></font>

    <font color="#000000"><b>endstruct</b></font>

    <font color="#000000"><b>function</b></font> <span style="background-color: #ffffff"><font color="#000000">test</font></span> <font color="#000000"><b>takes</b></font> <font color="#7777cc"><b>nothing</b></font> <font color="#000000"><b>returns</b></font> <font color="#7777cc"><b>nothing</b></font>
     <font color="#000000"><b>local</b></font> <span style="background-color: #ffffff"><font color="#000000">encap</font></span> <span style="background-color: #ffffff"><font color="#000000">e</font></span>=<span style="background-color: #ffffff"><font color="#000000">encap</font></span><font color="#000066">.</font><span style="background-color: #ffffff"><font color="#000000">altcreate</font></span>(<font color="#000066">5</font>,<font color="#000066">12.4</font>,<font color="#000066">78.0</font>)
         <font color="#000000"><b>call</b></font> <span style="background-color: #ffffff"><font color="#000000">BJDebugMsg</font></span>(<span style="background-color: #ffffff"><font color="#000000">R2S</font></span>(<span style="background-color: #ffffff"><font color="#000000">e</font></span><font color="#000066">.</font><span style="background-color: #ffffff"><font color="#000000">a</font></span>)+<font color="#0000cc"><i>" , "</i></font>+<span style="background-color: #ffffff"><font color="#000000">R2S</font></span>(<span style="background-color: #ffffff"><font color="#000000">e</font></span><font color="#000066">.</font><span style="background-color: #ffffff"><font color="#000000">c</font></span>))
    <font color="#000000"><b>endfunction</b></font>
</pre>

<p>You might notice that the usual create() syntax works like an static method, and destroy() can work as static or instance method</p>

<p>You can override the static method create by declaring your own one, once you do it, you might require another method just to allocate a unique id for the struct, this is the allocate() static method which is added by default to all structs, it is a private method. When a struct does not have an specific create method declared, jasshelper will use allocate directly when .create is called.</p>

<p>Since 0.9.Z.1 you may also override the destroy method by declaring your own one. Then use deallocate to call the normal destroy method.</p>

<pre><font color="#000000"><b>struct</b></font> <span style="background-color: #ffffff"><font color="#000000">vec</font></span>
   <font color="#7777cc"><b>real</b></font> <span style="background-color: #ffffff"><font color="#000000">x</font></span>
   <font color="#7777cc"><b>real</b></font> <span style="background-color: #ffffff"><font color="#000000">y</font></span>
   <font color="#7777cc"><b>real</b></font> <span style="background-color: #ffffff"><font color="#000000">z</font></span>

   <font color="#008800">// static method create must return a value of the struct's type</font>
   <font color="#008800">// create may have arguments.</font>
   <font color="#000000"><b>static</b></font> <font color="#000000"><b>method</b></font> <span style="background-color: #ffffff"><font color="#000000">create</font></span> <font color="#000000"><b>takes</b></font> <font color="#7777cc"><b>real</b></font> <span style="background-color: #ffffff"><font color="#000000">ax</font></span>, <font color="#7777cc"><b>real</b></font> <span style="background-color: #ffffff"><font color="#000000">ay</font></span>, <font color="#7777cc"><b>real</b></font> <span style="background-color: #ffffff"><font color="#000000">az</font></span> <font color="#000000"><b>returns</b></font> <span style="background-color: #ffffff"><font color="#000000">vec</font></span>
     <font color="#000000"><b>local</b></font> <span style="background-color: #ffffff"><font color="#000000">vec</font></span> <span style="background-color: #ffffff"><font color="#000000">r</font></span>= <span style="background-color: #ffffff"><font color="#000000">vec</font></span><font color="#000066">.</font><span style="background-color: #ffffff"><font color="#000000">allocate</font></span>() <font color="#008800">//allocate() is private and</font>
                                 <font color="#008800">//it gets a unique id for the struct</font>
         <font color="#000000"><b>set</b></font> <span style="background-color: #ffffff"><font color="#000000">r</font></span><font color="#000066">.</font><span style="background-color: #ffffff"><font color="#000000">x</font></span>=<span style="background-color: #ffffff"><font color="#000000">ax</font></span>
         <font color="#000000"><b>set</b></font> <span style="background-color: #ffffff"><font color="#000000">r</font></span><font color="#000066">.</font><span style="background-color: #ffffff"><font color="#000000">y</font></span>=<span style="background-color: #ffffff"><font color="#000000">ay</font></span>
         <font color="#000000"><b>set</b></font> <span style="background-color: #ffffff"><font color="#000000">r</font></span><font color="#000066">.</font><span style="background-color: #ffffff"><font color="#000000">z</font></span>=<span style="background-color: #ffffff"><font color="#000000">az</font></span>

     <font color="#000000"><b>return</b></font> <span style="background-color: #ffffff"><font color="#000000">r</font></span>
   <font color="#000000"><b>endmethod</b></font>

<font color="#000000"><b>endstruct</b></font>

<font color="#000000"><b>function</b></font> <span style="background-color: #ffffff"><font color="#000000">test</font></span> <font color="#000000"><b>takes</b></font> <font color="#7777cc"><b>nothing</b></font> <font color="#000000"><b>returns</b></font> <font color="#7777cc"><b>nothing</b></font>
 <font color="#000000"><b>local</b></font> <span style="background-color: #ffffff"><font color="#000000">vec</font></span> <span style="background-color: #ffffff"><font color="#000000">v</font></span>= <span style="background-color: #ffffff"><font color="#000000">vec</font></span><font color="#000066">.</font><span style="background-color: #ffffff"><font color="#000000">create</font></span>(<font color="#000066">1.0</font> , <font color="#000066">0.0</font> , -<font color="#000066">1.0</font> )

    <font color="#000000"><b>call</b></font> <span style="background-color: #ffffff"><font color="#000000">BJDebugMsg</font></span>( <span style="background-color: #ffffff"><font color="#000000">R2S</font></span>(<span style="background-color: #ffffff"><font color="#000000">v</font></span><font color="#000066">.</font><span style="background-color: #ffffff"><font color="#000000">z</font></span>) )

    <font color="#000000"><b>call</b></font> <span style="background-color: #ffffff"><font color="#000000">v</font></span><font color="#000066">.</font><span style="background-color: #ffffff"><font color="#000000">destroy</font></span>()
<font color="#000000"><b>endfunction</b></font>
</pre>

<p>Static methods that take nothing can also be used as code values</p>

<pre>    <font color="#000000"><b>struct</b></font> <span style="background-color: #ffffff"><font color="#000000">something</font></span>
        <font color="#000000"><b>static</b></font> <font color="#000000"><b>method</b></font> <span style="background-color: #ffffff"><font color="#000000">bb</font></span> <font color="#000000"><b>takes</b></font> <font color="#7777cc"><b>nothing</b></font> <font color="#000000"><b>returns</b></font> <font color="#7777cc"><b>nothing</b></font>
            <font color="#000000"><b>call</b></font> <span style="background-color: #ffffff"><font color="#000000">BJDebugMsg</font></span>(<font color="#0000cc"><i>"!!"</i></font>)
        <font color="#000000"><b>endmethod</b></font>
    <font color="#000000"><b>endstruct</b></font>

    <font color="#000000"><b>function</b></font> <span style="background-color: #ffffff"><font color="#000000">atest</font></span> <font color="#000000"><b>takes</b></font> <font color="#7777cc"><b>nothing</b></font> <font color="#000000"><b>returns</b></font> <font color="#7777cc"><b>nothing</b></font>
     <font color="#000000"><b>local</b></font> <font color="#7777cc"><b>trigger</b></font> <span style="background-color: #ffffff"><font color="#000000">t</font></span>=<span style="background-color: #ffffff"><font color="#000000">CreateTrigger</font></span>()
         <font color="#000000"><b>call</b></font> <span style="background-color: #ffffff"><font color="#000000">TriggerAddAction</font></span>(<span style="background-color: #ffffff"><font color="#000000">t</font></span>, <font color="#000000"><b>function</b></font> <span style="background-color: #ffffff"><font color="#000000">something</font></span><font color="#000066">.</font><span style="background-color: #ffffff"><font color="#000000">bb</font></span>)
         <font color="#000000"><b>call</b></font> <span style="background-color: #ffffff"><font color="#000000">TriggerExecute</font></span>(<span style="background-color: #ffffff"><font color="#000000">t</font></span>)
    <font color="#000000"><b>endfunction</b></font>
</pre>

<h4 style="color: black"><a name="strucondes"></a>The onDestroy method</h4>

<p>There is no actual syntax for destructors, but there is a rule and it is that if the struct has a method called onDestroy, it is always automatically called when .destroy() is issued on an instance.</p>

<p>It is useful to have onDestroy when an instance of the type may hold things that have to be correctly cleaned, it saves time and even makes things safer.</p>

<pre>    <font color="#000000"><b>struct</b></font> <span style="background-color: #ffffff"><font color="#000000">sta</font></span>
        <font color="#7777cc"><b>real</b></font> <span style="background-color: #ffffff"><font color="#000000">a</font></span>
        <font color="#7777cc"><b>real</b></font> <span style="background-color: #ffffff"><font color="#000000">b</font></span>
    <font color="#000000"><b>endstruct</b></font>

    <font color="#000000"><b>struct</b></font> <span style="background-color: #ffffff"><font color="#000000">stb</font></span>
        <span style="background-color: #ffffff"><font color="#000000">sta</font></span> <span style="background-color: #ffffff"><font color="#000000">H</font></span>=<font color="#000066">0</font>
        <span style="background-color: #ffffff"><font color="#000000">sta</font></span> <span style="background-color: #ffffff"><font color="#000000">K</font></span>=<font color="#000066">0</font>

        <font color="#000000"><b>method</b></font> <span style="background-color: #ffffff"><font color="#000000">onDestroy</font></span> <font color="#000000"><b>takes</b></font> <font color="#7777cc"><b>nothing</b></font> <font color="#000000"><b>returns</b></font> <font color="#7777cc"><b>nothing</b></font>
            <font color="#000000"><b>if</b></font> (<span style="background-color: #ffffff"><font color="#000000">H</font></span>!=<font color="#000066">0</font>) <font color="#000000"><b>then</b></font>
                <font color="#000000"><b>call</b></font> <span style="background-color: #ffffff"><font color="#000000">sta</font></span><font color="#000066">.</font><span style="background-color: #ffffff"><font color="#000000">destroy</font></span>(<span style="background-color: #ffffff"><font color="#000000">H</font></span>)
            <font color="#000000"><b>endif</b></font>
            <font color="#000000"><b>if</b></font> (<span style="background-color: #ffffff"><font color="#000000">K</font></span>!=<font color="#000066">0</font>) <font color="#000000"><b>then</b></font>
                <font color="#000000"><b>call</b></font> <span style="background-color: #ffffff"><font color="#000000">sta</font></span><font color="#000066">.</font><span style="background-color: #ffffff"><font color="#000000">destroy</font></span>(<span style="background-color: #ffffff"><font color="#000000">K</font></span>)
            <font color="#000000"><b>endif</b></font>
        <font color="#000000"><b>endmethod</b></font>
    <font color="#000000"><b>endstruct</b></font>

</pre>

<p>In the above example, it is only needed to destroy the object of type stb and it would automatically destroy the attached objects of type sta if present.</p>

<h4 style="color: black"><a name="struconini"></a>The onInit method</h4>

<p>It is usual to need some initialization to be done to an struct's static members during map initialization, you can use an <strong>static onInit</strong> method to make code execute during map initialization.</p>

<p>Notice struct initializations are executed before any library initializer, if you require a library initializer to be executed before your initialization, use a library initializer instead. The relative order between different struct initializers depends on the location they are found in the map script, therefore they actually depend on things like libraries as well (A struct initializer inside a library will run before the initializers inside other libraries that require it and also before initializers inside scopes).</p>

<pre>     <font color="#000000"><b>struct</b></font> <span style="background-color: #ffffff"><font color="#000000">A</font></span>
        <font color="#000000"><b>static</b></font> <font color="#0055aa"><b>integer</b></font> <font color="#0055aa"><b>array</b></font> <span style="background-color: #ffffff"><font color="#000000">ko</font></span>

        <font color="#000000"><b>private static</b></font> <font color="#000000"><b>method</b></font> <span style="background-color: #ffffff"><font color="#000000">onInit</font></span> <font color="#000000"><b>takes</b></font> <font color="#0055aa"><b>nothing</b></font> <font color="#000000"><b>returns</b></font> <font color="#0055aa"><b>nothing</b></font> <font color="#008800">//may be public as well</font>
         <font color="#000000"><b>local</b></font> <font color="#0055aa"><b>integer</b></font> <span style="background-color: #ffffff"><font color="#000000">i</font></span>=<font color="#0000aa">1000</font>
             <font color="#000000"><b>loop</b></font>
                 <font color="#000000"><b>exitwhen</b></font> (<span style="background-color: #ffffff"><font color="#000000">i</font></span>&lt;<font color="#0000aa">0</font>)
                 <font color="#000000"><b>set</b></font> <span style="background-color: #ffffff"><font color="#000000">A</font></span><font color="#0000aa">.</font><span style="background-color: #ffffff"><font color="#000000">ko</font></span>[<span style="background-color: #ffffff"><font color="#000000">i</font></span>]=<span style="background-color: #ffffff"><font color="#000000">i</font></span>*<font color="#0000aa">2</font>
                 <font color="#000000"><b>set</b></font> <span style="background-color: #ffffff"><font color="#000000">i</font></span>=<span style="background-color: #ffffff"><font color="#000000">i</font></span>-<font color="#0000aa">1</font>
             <font color="#000000"><b>endloop</b></font>
        <font color="#000000"><b>endmethod</b></font>
     <font color="#000000"><b>endstruct</b></font>
</pre>

<h4 style="color: black"><a name="interfs"></a>Interfaces</h4>

<p>Polymorphism is an OOP concept in which different object classes may have the same action, although the action is different, the action gets the same name. For example both an ant and a person run, but they are pretty different objects and the run action is implemented in different ways.</p>

<p>An interface is like a set of rules struct types follow and allow you to call actions of an struct without really knowing the exact type of the struct.</p>

<pre>    <font color="#000000"><b>interface</b></font> <span style="background-color: #ffffff"><font color="#000000">printable</font></span>
        <font color="#000000"><b>method</b></font> <span style="background-color: #ffffff"><font color="#000000">toString</font></span> <font color="#000000"><b>takes</b></font> <font color="#7777cc"><b>nothing</b></font> <font color="#000000"><b>returns</b></font> <font color="#7777cc"><b>string</b></font>
    <font color="#000000"><b>endinterface</b></font>

    <font color="#000000"><b>struct</b></font> <span style="background-color: #ffffff"><font color="#000000">singleint</font></span> <font color="#000000"><b>extends</b></font> <span style="background-color: #ffffff"><font color="#000000">printable</font></span>
        <font color="#7777cc"><b>integer</b></font> <span style="background-color: #ffffff"><font color="#000000">v</font></span>
        <font color="#000000"><b>method</b></font> <span style="background-color: #ffffff"><font color="#000000">toString</font></span> <font color="#000000"><b>takes</b></font> <font color="#7777cc"><b>nothing</b></font> <font color="#000000"><b>returns</b></font> <font color="#7777cc"><b>string</b></font>
            <font color="#000000"><b>return</b></font> <span style="background-color: #ffffff"><font color="#000000">I2S</font></span>(<font color="#000066">this</font><font color="#000066">.</font><span style="background-color: #ffffff"><font color="#000000">v</font></span>)
        <font color="#000000"><b>endmethod</b></font>
    <font color="#000000"><b>endstruct</b></font>

    <font color="#000000"><b>struct</b></font> <span style="background-color: #ffffff"><font color="#000000">intpair</font></span> <font color="#000000"><b>extends</b></font> <span style="background-color: #ffffff"><font color="#000000">printable</font></span>
        <font color="#7777cc"><b>integer</b></font> <span style="background-color: #ffffff"><font color="#000000">a</font></span>
        <font color="#7777cc"><b>integer</b></font> <span style="background-color: #ffffff"><font color="#000000">b</font></span>

        <font color="#000000"><b>method</b></font> <span style="background-color: #ffffff"><font color="#000000">toString</font></span> <font color="#000000"><b>takes</b></font> <font color="#7777cc"><b>nothing</b></font> <font color="#000000"><b>returns</b></font> <font color="#7777cc"><b>string</b></font>
            <font color="#000000"><b>return</b></font> <font color="#0000cc"><i>"("</i></font>+<span style="background-color: #ffffff"><font color="#000000">I2S</font></span>(<font color="#000066">this</font><font color="#000066">.</font><span style="background-color: #ffffff"><font color="#000000">a</font></span>)+<font color="#0000cc"><i>","</i></font>+<span style="background-color: #ffffff"><font color="#000000">I2S</font></span>(<font color="#000066">this</font><font color="#000066">.</font><span style="background-color: #ffffff"><font color="#000000">b</font></span>)+<font color="#0000cc"><i>")"</i></font>
        <font color="#000000"><b>endmethod</b></font>
    <font color="#000000"><b>endstruct</b></font>

    <font color="#000000"><b>function</b></font> <span style="background-color: #ffffff"><font color="#000000">printmany</font></span> <font color="#000000"><b>takes</b></font> <span style="background-color: #ffffff"><font color="#000000">printable</font></span> <span style="background-color: #ffffff"><font color="#000000">a</font></span>, <span style="background-color: #ffffff"><font color="#000000">printable</font></span> <span style="background-color: #ffffff"><font color="#000000">b</font></span>, <span style="background-color: #ffffff"><font color="#000000">printable</font></span> <span style="background-color: #ffffff"><font color="#000000">c</font></span> <font color="#000000"><b>returns</b></font> <font color="#7777cc"><b>nothing</b></font>
        <font color="#000000"><b>call</b></font> <span style="background-color: #ffffff"><font color="#000000">BJDebugMsg</font></span>( <span style="background-color: #ffffff"><font color="#000000">a</font></span><font color="#000066">.</font><span style="background-color: #ffffff"><font color="#000000">toString</font></span>()+<font color="#0000cc"><i>" - "</i></font>+<span style="background-color: #ffffff"><font color="#000000">b</font></span><font color="#000066">.</font><span style="background-color: #ffffff"><font color="#000000">toString</font></span>()+<font color="#0000cc"><i>" - "</i></font>+<span style="background-color: #ffffff"><font color="#000000">c</font></span><font color="#000066">.</font><span style="background-color: #ffffff"><font color="#000000">toString</font></span>())
    <font color="#000000"><b>endfunction</b></font>


    <font color="#000000"><b>function</b></font> <span style="background-color: #ffffff"><font color="#000000">test</font></span> <font color="#000000"><b>takes</b></font> <font color="#7777cc"><b>nothing</b></font> <font color="#000000"><b>returns</b></font> <font color="#7777cc"><b>nothing</b></font>
     <font color="#000000"><b>local</b></font> <span style="background-color: #ffffff"><font color="#000000">singleint</font></span> <span style="background-color: #ffffff"><font color="#000000">x</font></span>=<span style="background-color: #ffffff"><font color="#000000">singleint</font></span><font color="#000066">.</font><span style="background-color: #ffffff"><font color="#000000">create</font></span>()
     <font color="#000000"><b>local</b></font> <span style="background-color: #ffffff"><font color="#000000">singleint</font></span> <span style="background-color: #ffffff"><font color="#000000">y</font></span>=<span style="background-color: #ffffff"><font color="#000000">singleint</font></span><font color="#000066">.</font><span style="background-color: #ffffff"><font color="#000000">create</font></span>()
     <font color="#000000"><b>local</b></font> <span style="background-color: #ffffff"><font color="#000000">intpair</font></span> <span style="background-color: #ffffff"><font color="#000000">z</font></span>=<span style="background-color: #ffffff"><font color="#000000">intpair</font></span><font color="#000066">.</font><span style="background-color: #ffffff"><font color="#000000">create</font></span>()

        <font color="#000000"><b>set</b></font> <span style="background-color: #ffffff"><font color="#000000">x</font></span><font color="#000066">.</font><span style="background-color: #ffffff"><font color="#000000">v</font></span>=<font color="#000066">56</font>
        <font color="#000000"><b>set</b></font> <span style="background-color: #ffffff"><font color="#000000">y</font></span><font color="#000066">.</font><span style="background-color: #ffffff"><font color="#000000">v</font></span>=<font color="#000066">12</font>
        <font color="#000000"><b>set</b></font> <span style="background-color: #ffffff"><font color="#000000">z</font></span><font color="#000066">.</font><span style="background-color: #ffffff"><font color="#000000">a</font></span>=<font color="#000066">45</font>
        <font color="#000000"><b>set</b></font> <span style="background-color: #ffffff"><font color="#000000">z</font></span><font color="#000066">.</font><span style="background-color: #ffffff"><font color="#000000">b</font></span>=<font color="#000066">12</font>

        <font color="#000000"><b>call</b></font> <span style="background-color: #ffffff"><font color="#000000">printmany</font></span>(<span style="background-color: #ffffff"><font color="#000000">x</font></span>,<span style="background-color: #ffffff"><font color="#000000">y</font></span>,<span style="background-color: #ffffff"><font color="#000000">z</font></span>)
    <font color="#000000"><b>endfunction</b></font>


</pre>

<p>The printmany function takes three arguments of type printable, it does not know exactly which types the objects are, only that they are of struct types that extend printable</p>

<p>The rule for an struct to follow the printable interface is that it has a toString() method, the printmany function can use that method even though it does not know the exact types of the arguments</p>

<p>The toString() method is different for singleint and intpair, when printmany is called it calls the correct version of toString() for each argument, the result for the above sample is : "56 - 12 - (45,12)".</p>

<p>Interfaces can have any number of methods and structs that extend them should implement all those methods, but can ther methods implemented as well.</p>

<p>It is illegal to declare onDestroy for an interface declaration, you can consider it to be automatically declared, you can use .destroy() on a variable of interface type and it will call the appropiate onDestroy method when necessary.</p>

<p>Interfaces can also implement variables, in this case interfaces allow some pseudo inheritance</p>

<pre>    <font color="#000000"><b>interface</b></font> <span style="background-color: #ffffff"><font color="#000000">withpos</font></span>
        <font color="#7777cc"><b>real</b></font> <span style="background-color: #ffffff"><font color="#000000">x</font></span>
        <font color="#7777cc"><b>real</b></font> <span style="background-color: #ffffff"><font color="#000000">y</font></span>
    <font color="#000000"><b>endinterface</b></font>

    <font color="#000000"><b>struct</b></font> <span style="background-color: #ffffff"><font color="#000000">rectangle</font></span> <font color="#000000"><b>extends</b></font> <span style="background-color: #ffffff"><font color="#000000">withpos</font></span>
        <font color="#7777cc"><b>real</b></font> <span style="background-color: #ffffff"><font color="#000000">a</font></span>
        <font color="#7777cc"><b>real</b></font> <span style="background-color: #ffffff"><font color="#000000">b</font></span>

        <font color="#000000"><b>static</b></font> <font color="#000000"><b>method</b></font> <span style="background-color: #ffffff"><font color="#000000">from</font></span> <font color="#000000"><b>takes</b></font> <font color="#7777cc"><b>real</b></font> <span style="background-color: #ffffff"><font color="#000000">x</font></span>, <font color="#7777cc"><b>real</b></font> <span style="background-color: #ffffff"><font color="#000000">y</font></span>, <font color="#7777cc"><b>real</b></font> <span style="background-color: #ffffff"><font color="#000000">a</font></span>, <font color="#7777cc"><b>real</b></font> <span style="background-color: #ffffff"><font color="#000000">b</font></span> <font color="#000000"><b>returns</b></font> <span style="background-color: #ffffff"><font color="#000000">rectangle</font></span>
         <font color="#000000"><b>local</b></font> <span style="background-color: #ffffff"><font color="#000000">rectangle</font></span> <span style="background-color: #ffffff"><font color="#000000">r</font></span>=<span style="background-color: #ffffff"><font color="#000000">rectangle</font></span><font color="#000066">.</font><span style="background-color: #ffffff"><font color="#000000">create</font></span>()
            <font color="#000000"><b>set</b></font> <span style="background-color: #ffffff"><font color="#000000">r</font></span><font color="#000066">.</font><span style="background-color: #ffffff"><font color="#000000">x</font></span>=<span style="background-color: #ffffff"><font color="#000000">x</font></span>
            <font color="#000000"><b>set</b></font> <span style="background-color: #ffffff"><font color="#000000">r</font></span><font color="#000066">.</font><span style="background-color: #ffffff"><font color="#000000">y</font></span>=<span style="background-color: #ffffff"><font color="#000000">y</font></span>
            <font color="#000000"><b>set</b></font> <span style="background-color: #ffffff"><font color="#000000">r</font></span><font color="#000066">.</font><span style="background-color: #ffffff"><font color="#000000">a</font></span>=<span style="background-color: #ffffff"><font color="#000000">a</font></span>
            <font color="#000000"><b>set</b></font> <span style="background-color: #ffffff"><font color="#000000">r</font></span><font color="#000066">.</font><span style="background-color: #ffffff"><font color="#000000">b</font></span>=<span style="background-color: #ffffff"><font color="#000000">b</font></span>
            <font color="#000000"><b>return</b></font> r
        <font color="#000000"><b>endmethod</b></font>

    <font color="#000000"><b>endstruct</b></font>

    <font color="#000000"><b>struct</b></font> <span style="background-color: #ffffff"><font color="#000000">circle</font></span> <font color="#000000"><b>extends</b></font> <span style="background-color: #ffffff"><font color="#000000">withpos</font></span>
        <font color="#7777cc"><b>real</b></font> <span style="background-color: #ffffff"><font color="#000000">radius</font></span><font color="#000066">=67.0</font>

        <font color="#000000"><b>static</b></font> <font color="#000000"><b>method</b></font> <span style="background-color: #ffffff"><font color="#000000">from</font></span> <font color="#000000"><b>takes</b></font> <font color="#7777cc"><b>real</b></font> <span style="background-color: #ffffff"><font color="#000000">x</font></span>, <font color="#7777cc"><b>real</b></font> <span style="background-color: #ffffff"><font color="#000000">y</font></span>, <font color="#7777cc"><b>real</b></font> <span style="background-color: #ffffff"><font color="#000000">rad</font></span> <font color="#000000"><b>returns</b></font> <span style="background-color: #ffffff"><font color="#000000">circle</font></span>
         <font color="#000000"><b>local</b></font> <span style="background-color: #ffffff"><font color="#000000">circle</font></span> <span style="background-color: #ffffff"><font color="#000000">r</font></span>=<span style="background-color: #ffffff"><font color="#000000">circle</font></span><font color="#000066">.</font><span style="background-color: #ffffff"><font color="#000000">create</font></span>()
            <font color="#000000"><b>set</b></font> <span style="background-color: #ffffff"><font color="#000000">r</font></span><font color="#000066">.</font><span style="background-color: #ffffff"><font color="#000000">x</font></span>=<span style="background-color: #ffffff"><font color="#000000">x</font></span>
            <font color="#000000"><b>set</b></font> <span style="background-color: #ffffff"><font color="#000000">r</font></span><font color="#000066">.</font><span style="background-color: #ffffff"><font color="#000000">y</font></span>=<span style="background-color: #ffffff"><font color="#000000">y</font></span>
            <font color="#000000"><b>set</b></font> <span style="background-color: #ffffff"><font color="#000000">r</font></span><font color="#000066">.</font><span style="background-color: #ffffff"><font color="#000000">radius</font></span>=<span style="background-color: #ffffff"><font color="#000000">rad</font></span>
            <font color="#000000"><b>return</b></font> r
        <font color="#000000"><b>endmethod</b></font>

    <font color="#000000"><b>endstruct</b></font>


    <font color="#000000"><b>function</b></font> <span style="background-color: #ffffff"><font color="#000000">distance</font></span> <font color="#000000"><b>takes</b></font> <span style="background-color: #ffffff"><font color="#000000">withpos</font></span> <span style="background-color: #ffffff"><font color="#000000">A</font></span>, <span style="background-color: #ffffff"><font color="#000000">withpos</font></span> <span style="background-color: #ffffff"><font color="#000000">B</font></span> <font color="#000000"><b>returns</b></font> <font color="#7777cc"><b>real</b></font>
     <font color="#000000"><b>local</b></font> <font color="#7777cc"><b>real</b></font> <span style="background-color: #ffffff"><font color="#000000">dy</font></span>=<span style="background-color: #ffffff"><font color="#000000">A</font></span><font color="#000066">.</font><span style="background-color: #ffffff"><font color="#000000">y</font></span>-<span style="background-color: #ffffff"><font color="#000000">B</font></span><font color="#000066">.</font><span style="background-color: #ffffff"><font color="#000000">y</font></span>
     <font color="#000000"><b>local</b></font> <font color="#7777cc"><b>real</b></font> <span style="background-color: #ffffff"><font color="#000000">dx</font></span>=<span style="background-color: #ffffff"><font color="#000000">A</font></span><font color="#000066">.</font><span style="background-color: #ffffff"><font color="#000000">x</font></span>-<span style="background-color: #ffffff"><font color="#000000">B</font></span><font color="#000066">.</font><span style="background-color: #ffffff"><font color="#000000">x</font></span>

     <font color="#000000"><b>return</b></font> <span style="background-color: #ffffff"><font color="#000000">SquareRoot</font></span>( <span style="background-color: #ffffff"><font color="#000000">dy</font></span>*<span style="background-color: #ffffff"><font color="#000000">dy</font></span>+<span style="background-color: #ffffff"><font color="#000000">dx</font></span>*<span style="background-color: #ffffff"><font color="#000000">dx</font></span>)
    <font color="#000000"><b>endfunction</b></font>

    <font color="#000000"><b>function</b></font> <span style="background-color: #ffffff"><font color="#000000">test</font></span> <font color="#000000"><b>takes</b></font> <font color="#7777cc"><b>nothing</b></font> <font color="#000000"><b>returns</b></font> <font color="#7777cc"><b>nothing</b></font>
     <font color="#000000"><b>local</b></font> <span style="background-color: #ffffff"><font color="#000000">circle</font></span> <span style="background-color: #ffffff"><font color="#000000">c</font></span>= <span style="background-color: #ffffff"><font color="#000000">circle</font></span><font color="#000066">.</font><span style="background-color: #ffffff"><font color="#000000">from</font></span>(<font color="#000066">12.0</font>, <font color="#000066">45.0</font> , <font color="#000066">13.0</font>)
     <font color="#000000"><b>local</b></font> <span style="background-color: #ffffff"><font color="#000000">rectangle</font></span> <span style="background-color: #ffffff"><font color="#000000">r</font></span> = <span style="background-color: #ffffff"><font color="#000000">rectangle</font></span><font color="#000066">.</font><span style="background-color: #ffffff"><font color="#000000">from</font></span> ( <font color="#000066">12.3</font> , <font color="#000066">67.8</font>, <font color="#000066">12.0</font> , <font color="#000066">10.0</font>)

         <font color="#000000"><b>call</b></font> <span style="background-color: #ffffff"><font color="#000000">BJDebugMsg</font></span>(<span style="background-color: #ffffff"><font color="#000000">R2S</font></span>(<span style="background-color: #ffffff"><font color="#000000">distance</font></span>(<span style="background-color: #ffffff"><font color="#000000">c</font></span>,<span style="background-color: #ffffff"><font color="#000000">r</font></span>)))

    <font color="#000000"><b>endfunction</b></font>
</pre>

<p>It is possible to acquire the type id of an instance of an struct that extends an interface, this type id is an integer number that is unique per struct type that extends that interface.</p>

<pre><font color="#000000"><b>interface</b></font> <span style="background-color: #ffffff"><font color="#000000">A</font></span>
    <font color="#7777cc"><b>integer</b></font> <span style="background-color: #ffffff"><font color="#000000">x</font></span>
<font color="#000000"><b>endinterface</b></font>

<font color="#000000"><b>struct</b></font> <span style="background-color: #ffffff"><font color="#000000">B</font></span> <font color="#000000"><b>extends</b></font> <span style="background-color: #ffffff"><font color="#000000">A</font></span>
    <font color="#7777cc"><b>integer</b></font> <span style="background-color: #ffffff"><font color="#000000">y</font></span>
<font color="#000000"><b>endstruct</b></font>

<font color="#000000"><b>struct</b></font> <span style="background-color: #ffffff"><font color="#000000">C</font></span> <font color="#000000"><b>extends</b></font> <span style="background-color: #ffffff"><font color="#000000">A</font></span>
    <font color="#7777cc"><b>integer</b></font> <span style="background-color: #ffffff"><font color="#000000">y</font></span>
    <font color="#7777cc"><b>integer</b></font> <span style="background-color: #ffffff"><font color="#000000">z</font></span>
<font color="#000000"><b>endstruct</b></font>

<font color="#000000"><b>function</b></font> <span style="background-color: #ffffff"><font color="#000000">test</font></span> <font color="#000000"><b>takes</b></font> <span style="background-color: #ffffff"><font color="#000000">A</font></span> <span style="background-color: #ffffff"><font color="#000000">inst</font></span> <font color="#000000"><b>returns</b></font> <font color="#7777cc"><b>nothing</b></font>
   <font color="#000000"><b>if</b></font> (<span style="background-color: #ffffff"><font color="#000000">inst</font></span><font color="#000066">.</font><span style="background-color: #ffffff"><font color="#000000">getType</font></span>()==<span style="background-color: #ffffff"><font color="#000000">C</font></span><font color="#000066">.</font><span style="background-color: #ffffff"><font color="#000000">typeid</font></span>) <font color="#000000"><b>then</b></font>
     <font color="#008800">// We know for sure inst is actually an instance of type C</font>
       <font color="#000000"><b>set</b></font> <span style="background-color: #ffffff"><font color="#000000">C</font></span>(<span style="background-color: #ffffff"><font color="#000000">inst</font></span>)<font color="#000066">.</font><span style="background-color: #ffffff"><font color="#000000">z</font></span>=<font color="#000066">5</font> <font color="#008800">//notice the typecast operator</font>
   <font color="#000000"><b>endif</b></font>
   <font color="#000000"><b>if</b></font> (<span style="background-color: #ffffff"><font color="#000000">inst</font></span><font color="#000066">.</font><span style="background-color: #ffffff"><font color="#000000">getType</font></span>()==<span style="background-color: #ffffff"><font color="#000000">B</font></span><font color="#000066">.</font><span style="background-color: #ffffff"><font color="#000000">typeid</font></span>) <font color="#000000"><b>then</b></font>
       <font color="#000000"><b>call</b></font> <span style="background-color: #ffffff"><font color="#000000">BJDebugMsg</font></span>(<font color="#0000cc"><i>"It was of type B with value "</i></font>+<span style="background-color: #ffffff"><font color="#000000">I2S</font></span>( <span style="background-color: #ffffff"><font color="#000000">B</font></span>(<span style="background-color: #ffffff"><font color="#000000">inst</font></span>)<font color="#000066">.</font><span style="background-color: #ffffff"><font color="#000000">y</font></span>  ) )
   <font color="#000000"><b>endif</b></font>
<font color="#000000"><b>endfunction</b></font>
</pre>

<p>In short, .getType() is a method that you use on instances of an object whose type extends an interface. And .typeid is an static constant set for struct types that extend an interface.</p>

<p>So, in the example we get to recognize that the given inst argument is of type C, then we can do the typecast and assignment.</p>

<p>There is another feature that uses typeids got another feature, and it is that interfaces got a constructor method that would create a new object given a correct typeid.</p>

<p>For 例子</p>

<pre><font color="#000000"><b>interface</b></font> <span style="background-color: #ffffff"><font color="#000000">myinterface</font></span>
    <font color="#000000"><b>method</b></font> <span style="background-color: #ffffff"><font color="#000000">msg</font></span> <font color="#000000"><b>takes</b></font> <font color="#0055aa"><b>nothing</b></font> <font color="#000000"><b>returns</b></font> <font color="#0055aa"><b>string</b></font>
<font color="#000000"><b>endinterface</b></font>

<font color="#000000"><b>struct</b></font> <span style="background-color: #ffffff"><font color="#000000">mystructA</font></span> <font color="#000000"><b>extends</b></font> <span style="background-color: #ffffff"><font color="#000000">myinterface</font></span>
    <font color="#000000"><b>method</b></font> <span style="background-color: #ffffff"><font color="#000000">msg</font></span> <font color="#000000"><b>takes</b></font> <font color="#0055aa"><b>nothing</b></font> <font color="#000000"><b>returns</b></font> <font color="#0055aa"><b>string</b></font>
        <font color="#000000"><b>return</b></font> <font color="#0000aa"><i>"oranges"</i></font>
    <font color="#000000"><b>endmethod</b></font>
<font color="#000000"><b>endstruct</b></font>

<font color="#000000"><b>struct</b></font> <span style="background-color: #ffffff"><font color="#000000">mystructB</font></span> <font color="#000000"><b>extends</b></font> <span style="background-color: #ffffff"><font color="#000000">myinterface</font></span>

   <font color="#0055aa"><b>string</b></font> <span style="background-color: #ffffff"><font color="#000000">x</font></span>
   <font color="#000000"><b>static</b></font> <font color="#000000"><b>method</b></font> <span style="background-color: #ffffff"><font color="#000000">create</font></span> <font color="#000000"><b>takes</b></font> <font color="#0055aa"><b>nothing</b></font> <font color="#000000"><b>returns</b></font> <span style="background-color: #ffffff"><font color="#000000">mystructB</font></span>
    <font color="#000000"><b>local</b></font> <span style="background-color: #ffffff"><font color="#000000">mystructB</font></span> <span style="background-color: #ffffff"><font color="#000000">m</font></span>=<span style="background-color: #ffffff"><font color="#000000">mystructB</font></span><font color="#0000aa">.</font><span style="background-color: #ffffff"><font color="#000000">allocate</font></span>()

       <font color="#000000"><b>set</b></font> <span style="background-color: #ffffff"><font color="#000000">m</font></span><font color="#0000aa">.</font><span style="background-color: #ffffff"><font color="#000000">x</font></span>=<font color="#0000aa"><i>"apples"</i></font>

       <font color="#000000"><b>return</b></font> <span style="background-color: #ffffff"><font color="#000000">m</font></span>
   <font color="#000000"><b>endmethod</b></font>

   <font color="#000000"><b>method</b></font> <span style="background-color: #ffffff"><font color="#000000">msg</font></span> <font color="#000000"><b>takes</b></font> <font color="#0055aa"><b>nothing</b></font> <font color="#000000"><b>returns</b></font> <font color="#0055aa"><b>string</b></font>
       <font color="#000000"><b>return</b></font> <font color="#0000aa">this</font><font color="#0000aa">.</font><span style="background-color: #ffffff"><font color="#000000">x</font></span>
   <font color="#000000"><b>endmethod</b></font>
<font color="#000000"><b>endstruct</b></font>

<font color="#000000"><b>struct</b></font> <span style="background-color: #ffffff"><font color="#000000">mystructC</font></span> <font color="#000000"><b>extends</b></font> <span style="background-color: #ffffff"><font color="#000000">myinterface</font></span>
   <font color="#0055aa"><b>string</b></font> <span style="background-color: #ffffff"><font color="#000000">x</font></span>

   <font color="#008800">//myinterface.create(...) can only use the default allocator or custom create</font>
   <font color="#008800">//methods that take nothing.</font>
   <font color="#008800">//</font>
   <font color="#008800">//this declaration is not going to be taken into account if mystructC</font>
   <font color="#008800">//is used in myinterface.create(...)</font>
   <font color="#008800">//</font>
   <font color="#000000"><b>static</b></font> <font color="#000000"><b>method</b></font> <span style="background-color: #ffffff"><font color="#000000">create</font></span> <font color="#000000"><b>takes</b></font> <font color="#0055aa"><b>string</b></font> <span style="background-color: #ffffff"><font color="#000000">astring</font></span> <font color="#000000"><b>returns</b></font> <span style="background-color: #ffffff"><font color="#000000">mystructC</font></span>
    <font color="#000000"><b>local</b></font> <span style="background-color: #ffffff"><font color="#000000">mystructB</font></span> <span style="background-color: #ffffff"><font color="#000000">m</font></span>=<span style="background-color: #ffffff"><font color="#000000">mystructB</font></span><font color="#0000aa">.</font><span style="background-color: #ffffff"><font color="#000000">allocate</font></span>()

       <font color="#000000"><b>set</b></font> <span style="background-color: #ffffff"><font color="#000000">m</font></span><font color="#0000aa">.</font><span style="background-color: #ffffff"><font color="#000000">x</font></span>=<span style="background-color: #ffffff"><font color="#000000">astring</font></span>

       <font color="#000000"><b>return</b></font> <span style="background-color: #ffffff"><font color="#000000">m</font></span>
   <font color="#000000"><b>endmethod</b></font>

   <font color="#000000"><b>method</b></font> <span style="background-color: #ffffff"><font color="#000000">msg</font></span> <font color="#000000"><b>takes</b></font> <font color="#0055aa"><b>nothing</b></font> <font color="#000000"><b>returns</b></font> <font color="#0055aa"><b>string</b></font>
       <font color="#000000"><b>return</b></font> <font color="#0000aa">this</font><font color="#0000aa">.</font><span style="background-color: #ffffff"><font color="#000000">x</font></span>
   <font color="#000000"><b>endmethod</b></font>
<font color="#000000"><b>endstruct</b></font>

<font color="#000000"><b>function</b></font> <span style="background-color: #ffffff"><font color="#000000">test</font></span> <font color="#000000"><b>takes</b></font> <font color="#0055aa"><b>nothing</b></font> <font color="#000000"><b>returns</b></font> <font color="#0055aa"><b>nothing</b></font>
 <font color="#000000"><b>local</b></font> <font color="#0055aa"><b>integer</b></font> <span style="background-color: #ffffff"><font color="#000000">T</font></span> = <span style="background-color: #ffffff"><font color="#000000">mystructB</font></span><font color="#0000aa">.</font><span style="background-color: #ffffff"><font color="#000000">typeid</font></span>
 <font color="#000000"><b>local</b></font> <span style="background-color: #ffffff"><font color="#000000">myinterface</font></span> <span style="background-color: #ffffff"><font color="#000000">A</font></span>


    <font color="#000000"><b>set</b></font> <span style="background-color: #ffffff"><font color="#000000">A</font></span>=<span style="background-color: #ffffff"><font color="#000000">myinterface</font></span><font color="#0000aa">.</font><span style="background-color: #ffffff"><font color="#000000">create</font></span>(<span style="background-color: #ffffff"><font color="#000000">mystructA</font></span><font color="#0000aa">.</font><span style="background-color: #ffffff"><font color="#000000">typeid</font></span>) <font color="#008800">//this is not that useful since mystructA.create() does the same</font>
    <font color="#000000"><b>call</b></font> <span style="background-color: #ffffff"><font color="#000000">BJDebugMsg</font></span>(<span style="background-color: #ffffff"><font color="#000000">A</font></span><font color="#0000aa">.</font><span style="background-color: #ffffff"><font color="#000000">msg</font></span>())

    <font color="#000000"><b>set</b></font> <span style="background-color: #ffffff"><font color="#000000">A</font></span>=<span style="background-color: #ffffff"><font color="#000000">myinterface</font></span><font color="#0000aa">.</font><span style="background-color: #ffffff"><font color="#000000">create</font></span>(<span style="background-color: #ffffff"><font color="#000000">T</font></span>) <font color="#008800">//this is more useful, we can create objects of variable types...</font>
    <font color="#000000"><b>call</b></font> <span style="background-color: #ffffff"><font color="#000000">BJDebugMsg</font></span>(<span style="background-color: #ffffff"><font color="#000000">B</font></span><font color="#0000aa">.</font><span style="background-color: #ffffff"><font color="#000000">msg</font></span>())

    <font color="#000000"><b>set</b></font> <span style="background-color: #ffffff"><font color="#000000">A</font></span>=<span style="background-color: #ffffff"><font color="#000000">myinterface</font></span><font color="#0000aa">.</font><span style="background-color: #ffffff"><font color="#000000">create</font></span>(<font color="#0000aa">122345</font>) <font color="#008800">//using invalid values or 0 will make .create return 0 (no object)</font>

    <font color="#000000"><b>set</b></font> <span style="background-color: #ffffff"><font color="#000000">A</font></span>=<span style="background-color: #ffffff"><font color="#000000">myinterface</font></span><font color="#0000aa">.</font><span style="background-color: #ffffff"><font color="#000000">create</font></span>(<span style="background-color: #ffffff"><font color="#000000">mystructC</font></span><font color="#0000aa">.</font><span style="background-color: #ffffff"><font color="#000000">typeid</font></span>) <font color="#008800">//note that this will not use mystructC.create, just </font>
                                               <font color="#008800">//mystructC.allocate, possibly causing errors, if this</font>
                                               <font color="#008800">//happens you can an error message in-game if you compile under debug mode</font>

    <font color="#000000"><b>call</b></font> <span style="background-color: #ffffff"><font color="#000000">BJDebugMsg</font></span>(<span style="background-color: #ffffff"><font color="#000000">C</font></span><font color="#0000aa">.</font><span style="background-color: #ffffff"><font color="#000000">msg</font></span>())

<font color="#000000"><b>endfunction</b></font>

</pre>

<p>If you plan using this feature, always be careful to handle 0 return values and also specify that it is better to use constructors without arguments on the interface's children.</p>

<p>It is also possible to declare the interface in a way that all the childs use a custom create method that returns nothing.</p>

<pre><font color="#000000"><b>interface</b></font> <span style="background-color: #ffffff"><font color="#000000">myinterface</font></span>
    <font color="#000000"><b>static</b></font> <font color="#000000"><b>method</b></font> <span style="background-color: #ffffff"><font color="#000000">create</font></span> <font color="#000000"><b>takes</b></font> <font color="#0055aa"><b>nothing</b></font>

    <font color="#000000"><b>method</b></font> <span style="background-color: #ffffff"><font color="#000000">qr</font></span> <font color="#000000"><b>takes</b></font> <font color="#0055aa"><b>unit</b></font> <span style="background-color: #ffffff"><font color="#000000">u</font></span> <font color="#000000"><b>returns</b></font> <font color="#0055aa"><b>nothing</b></font>
<font color="#000000"><b>endinterface</b></font>

<font color="#000000"><b>struct</b></font> <span style="background-color: #ffffff"><font color="#000000">st1</font></span> <font color="#000000"><b>extends</b></font> <span style="background-color: #ffffff"><font color="#000000">myinterface</font></span>

    <font color="#000000"><b>static</b></font> <font color="#000000"><b>method</b></font> <span style="background-color: #ffffff"><font color="#000000">create</font></span> <font color="#000000"><b>takes</b></font> <font color="#0055aa"><b>nothing</b></font> <font color="#000000"><b>returns</b></font> <span style="background-color: #ffffff"><font color="#000000">st1</font></span> <font color="#008800">//legal</font>
        <font color="#000000"><b>return</b></font> <span style="background-color: #ffffff"><font color="#000000">st1</font></span><font color="#0000aa">.</font><span style="background-color: #ffffff"><font color="#000000">allocate</font></span>()
    <font color="#000000"><b>endmethod</b></font>

    <font color="#000000"><b>method</b></font> <span style="background-color: #ffffff"><font color="#000000">qr</font></span> <font color="#000000"><b>takes</b></font> <font color="#0055aa"><b>unit</b></font> <span style="background-color: #ffffff"><font color="#000000">u</font></span> <font color="#000000"><b>returns</b></font> <font color="#0055aa"><b>nothing</b></font>
        <font color="#000000"><b>call</b></font> <span style="background-color: #ffffff"><font color="#000000">KillUnit</font></span>(<span style="background-color: #ffffff"><font color="#000000">u</font></span>)
    <font color="#000000"><b>endmethod</b></font>
<font color="#000000"><b>endstruct</b></font>


<font color="#000000"><b>struct</b></font> <span style="background-color: #ffffff"><font color="#000000">st2</font></span> <font color="#000000"><b>extends</b></font> <span style="background-color: #ffffff"><font color="#000000">myinterface</font></span>
 <font color="#0055aa"><b>integer</b></font> <span style="background-color: #ffffff"><font color="#000000">k</font></span>

    <font color="#000000"><b>static</b></font> <font color="#000000"><b>method</b></font> <span style="background-color: #ffffff"><font color="#000000">create</font></span> <font color="#000000"><b>takes</b></font> <font color="#0055aa"><b>integer</b></font> <span style="background-color: #ffffff"><font color="#000000">f</font></span>, <font color="#0055aa"><b>integer</b></font> <span style="background-color: #ffffff"><font color="#000000">k</font></span> <font color="#000000"><b>returns</b></font> <span style="background-color: #ffffff"><font color="#000000">st2</font></span> <font color="#008800">//not legal</font>
     <font color="#000000"><b>local</b></font> <span style="background-color: #ffffff"><font color="#000000">st2</font></span> <span style="background-color: #ffffff"><font color="#000000">s</font></span>=<span style="background-color: #ffffff"><font color="#000000">st2</font></span><font color="#0000aa">.</font><span style="background-color: #ffffff"><font color="#000000">allocate</font></span>()
        <font color="#000000"><b>set</b></font> <span style="background-color: #ffffff"><font color="#000000">st2</font></span><font color="#0000aa">.</font><span style="background-color: #ffffff"><font color="#000000">k</font></span>=<span style="background-color: #ffffff"><font color="#000000">f</font></span>+<span style="background-color: #ffffff"><font color="#000000">k</font></span>*<span style="background-color: #ffffff"><font color="#000000">f</font></span>
     <font color="#000000"><b>return</b></font> <span style="background-color: #ffffff"><font color="#000000">st2</font></span>
    <font color="#000000"><b>endmethod</b></font>

    <font color="#000000"><b>method</b></font> <span style="background-color: #ffffff"><font color="#000000">qr</font></span> <font color="#000000"><b>takes</b></font> <font color="#0055aa"><b>unit</b></font> <span style="background-color: #ffffff"><font color="#000000">u</font></span> <font color="#000000"><b>returns</b></font> <font color="#0055aa"><b>nothing</b></font>
        <font color="#000000"><b>call</b></font> <span style="background-color: #ffffff"><font color="#000000">ExplodeUnitBJ</font></span>(<span style="background-color: #ffffff"><font color="#000000">u</font></span>)
    <font color="#000000"><b>endmethod</b></font>
<font color="#000000"><b>endstruct</b></font>

</pre>

<p>Interface methods allow you to use the <b>defaults</b> keyword. The <b>defaults</b> keyword allows methods to be optional when implementing the child struct. So if the method is not present in the child struct it will not show syntax errors requesting the method to be implemented. Instead we will implement a default empty method.</p>

<p><b>defaults</b> is followed by "nothing" or by a value depending on the return type of the method (if the method returns nothing then it should default nothing, else it should default a value). <b>defaults</b> only supports constant values.</p>

<pre><span style="font-weight: bold;color: #000000;">interface</span><span style="color: #000000;"> whattodo</span>
<span style="color: #000000;">    </span><span style="font-weight: bold;color: #000000;">method</span><span style="color: #000000;"> onStrike </span><span style="font-weight: bold;color: #000000;">takes</span><span style="color: #000000;"> </span><span style="font-weight: bold;color: #3b71bd;">real</span><span style="color: #000000;"> x, </span><span style="font-weight: bold;color: #3b71bd;">real</span><span style="color: #000000;"> y </span><span style="font-weight: bold;color: #000000;">returns</span><span style="color: #000000;"> </span><span style="font-weight: bold;color: #3b71bd;">boolean</span><span style="color: #000000;"> </span><span style="font-weight: bold;color: #000000;">defaults</span><span style="color: #000000;"> </span><span style="font-weight: bold;color: #0095ff;">false</span>
<span style="color: #000000;">    </span><span style="font-weight: bold;color: #000000;">method</span><span style="color: #000000;"> onBegin  </span><span style="font-weight: bold;color: #000000;">takes</span><span style="color: #000000;"> </span><span style="font-weight: bold;color: #3b71bd;">real</span><span style="color: #000000;"> x, </span><span style="font-weight: bold;color: #3b71bd;">real</span><span style="color: #000000;"> y </span><span style="font-weight: bold;color: #000000;">returns</span><span style="color: #000000;"> </span><span style="font-weight: bold;color: #3b71bd;">nothing</span><span style="color: #000000;"> </span><span style="font-weight: bold;color: #000000;">defaults</span><span style="color: #000000;"> </span><span style="font-weight: bold;color: #3b71bd;">nothing</span>

<span style="color: #000000;">    </span><span style="font-weight: bold;color: #000000;">method</span><span style="color: #000000;"> onFinish </span><span style="font-weight: bold;color: #000000;">takes</span><span style="color: #000000;"> </span><span style="font-weight: bold;color: #3b71bd;">nothing</span><span style="color: #000000;"> </span><span style="font-weight: bold;color: #000000;">returns</span><span style="color: #000000;"> </span><span style="font-weight: bold;color: #3b71bd;">nothing</span>
<span style="font-weight: bold;color: #000000;">endinterface</span>

<span style="font-weight: bold;color: #000000;">struct</span><span style="color: #000000;"> A </span><span style="font-weight: bold;color: #000000;">extends</span><span style="color: #000000;"> whattodo </span><span style="font-style: italic;color: #126714;">//don't forget the extends...</span>

<span style="color: #000000;">    </span><span style="font-weight: bold;color: #000000;">method</span><span style="color: #000000;"> onFinish </span><span style="font-weight: bold;color: #000000;">takes</span><span style="color: #000000;"> </span><span style="font-weight: bold;color: #3b71bd;">nothing</span><span style="color: #000000;"> </span><span style="font-weight: bold;color: #000000;">returns</span><span style="color: #000000;"> </span><span style="font-weight: bold;color: #3b71bd;">nothing</span><span style="color: #000000;"> </span><span style="font-style: italic;color: #126714;">//must be implemented</span>
<span style="color: #000000;">        </span><span style="font-style: italic;color: #126714;">//.. code</span>
<span style="color: #000000;">    </span><span style="font-weight: bold;color: #000000;">endmethod</span>

<span style="color: #000000;">    </span><span style="font-style: italic;color: #126714;">// We are allowed to add onBegin, but not forced to</span>
<span style="color: #000000;">    </span><span style="font-weight: bold;color: #000000;">method</span><span style="color: #000000;"> onBegin </span><span style="font-weight: bold;color: #000000;">takes</span><span style="color: #000000;"> </span><span style="font-weight: bold;color: #3b71bd;">real</span><span style="color: #000000;"> x, </span><span style="font-weight: bold;color: #3b71bd;">real</span><span style="color: #000000;"> y </span><span style="font-weight: bold;color: #000000;">returns</span><span style="color: #000000;"> </span><span style="font-weight: bold;color: #3b71bd;">nothing</span>

<span style="color: #000000;">        </span><span style="font-style: italic;color: #126714;">//.. code </span>
<span style="color: #000000;">    </span><span style="font-weight: bold;color: #000000;">endmethod</span>

<span style="color: #000000;">    </span><span style="font-style: italic;color: #126714;">// when somebody calls .onStrike on a whattodo of type A, it will return false</span>
<span style="font-weight: bold;color: #000000;">endstruct</span>

<span style="font-weight: bold;color: #000000;">struct</span><span style="color: #000000;"> B </span><span style="font-weight: bold;color: #000000;">extends</span><span style="color: #000000;"> whattodo</span>
<span style="color: #000000;">    </span><span style="font-weight: bold;color: #000000;">method</span><span style="color: #000000;"> onFinish </span><span style="font-weight: bold;color: #000000;">takes</span><span style="color: #000000;"> </span><span style="font-weight: bold;color: #3b71bd;">nothing</span><span style="color: #000000;"> </span><span style="font-weight: bold;color: #000000;">returns</span><span style="color: #000000;"> </span><span style="font-weight: bold;color: #3b71bd;">nothing</span><span style="color: #000000;"> </span><span style="font-style: italic;color: #126714;">//must be implemented</span>
<span style="color: #000000;">        </span><span style="font-style: italic;color: #126714;">//.. code</span>
<span style="color: #000000;">    </span><span style="font-weight: bold;color: #000000;">endmethod</span>

<span style="color: #000000;">    </span><span style="font-style: italic;color: #126714;">// when somebody calls .onBegin on a whattodo of type A, it will do nothing</span>
<span style="font-weight: bold;color: #000000;">endstruct</span></pre>

<h4 style="color: black"><a name="operover"></a>Operator making</h4>

<p>Jasshelper allows you to declare custom operators for your structs, these operators would then be converted to method calls, vJass currently allows operators for &lt;, &gt; , array set and array get.</p>

<p>The official name for this process (In wikipedia and books) is operator overloading. In the case of vJass, An overloaded operator is a method, but it gets operator as name, after the operator keyword you specify the operator being overloaded.</p>

<p>An example is worth 1000 words:</p>

<pre>
    <font color="#000000"><b>struct</b></font> <span style="background-color: #ffffff"><font color="#000000">operatortest</font></span>
        <font color="#7777cc"><b>string</b></font> <span style="background-color: #ffffff"><font color="#000000">str</font></span>=<font color="#0000cc"><i>""</i></font>

        <font color="#000000"><b>method</b></font> <font color="#000000"><b>operator</b></font> [] <font color="#000000"><b>takes</b></font> <font color="#7777cc"><b>integer</b></font> <span style="background-color: #ffffff"><font color="#000000">i</font></span> <font color="#000000"><b>returns</b></font> <font color="#7777cc"><b>string</b></font>
            <font color="#000000"><b>return</b></font> <span style="background-color: #ffffff"><font color="#000000">SubString</font></span>(<font color="#000066">.</font><span style="background-color: #ffffff"><font color="#000000">str</font></span>,<span style="background-color: #ffffff"><font color="#000000">i</font></span>,<span style="background-color: #ffffff"><font color="#000000">i</font></span>+<font color="#000066">1</font>)
        <font color="#000000"><b>endmethod</b></font>

        <font color="#000000"><b>method</b></font> <font color="#000000"><b>operator</b></font>[]= <font color="#000000"><b>takes</b></font> <font color="#7777cc"><b>integer</b></font> <span style="background-color: #ffffff"><font color="#000000">i</font></span>, <font color="#7777cc"><b>string</b></font> <span style="background-color: #ffffff"><font color="#000000">ch</font></span> <font color="#000000"><b>returns</b></font> <font color="#7777cc"><b>nothing</b></font>
            <font color="#000000"><b>set</b></font> <font color="#000066">.</font><span style="background-color: #ffffff"><font color="#000000">str</font></span>=<span style="background-color: #ffffff"><font color="#000000">SubString</font></span>(<font color="#000066">.</font><span style="background-color: #ffffff"><font color="#000000">str</font></span>,<font color="#000066">0</font>,<span style="background-color: #ffffff"><font color="#000000">i</font></span>)+<span style="background-color: #ffffff"><font color="#000000">ch</font></span>+<span style="background-color: #ffffff"><font color="#000000">SubString</font></span>(<font color="#000066">.</font><span style="background-color: #ffffff"><font color="#000000">str</font></span>,<span style="background-color: #ffffff"><font color="#000000">i</font></span>+<font color="#000066">1</font>,<span style="background-color: #ffffff"><font color="#000000">StringLength</font></span>(<font color="#000066">.</font><span style="background-color: #ffffff"><font color="#000000">str</font></span>)-<span style="background-color: #ffffff"><font color="#000000">i</font></span>)
        <font color="#000000"><b>endmethod</b></font>

    <font color="#000000"><b>endstruct</b></font>


    <font color="#000000"><b>function</b></font> <span style="background-color: #ffffff"><font color="#000000">test</font></span> <font color="#000000"><b>takes</b></font> <font color="#7777cc"><b>nothing</b></font> <font color="#000000"><b>returns</b></font> <font color="#7777cc"><b>nothing</b></font>
     <font color="#000000"><b>local</b></font> <span style="background-color: #ffffff"><font color="#000000">operatortest</font></span> <span style="background-color: #ffffff"><font color="#000000">x</font></span>=<span style="background-color: #ffffff"><font color="#000000">operatortest</font></span><font color="#000066">.</font><span style="background-color: #ffffff"><font color="#000000">create</font></span>()
        <font color="#000000"><b>set</b></font> <span style="background-color: #ffffff"><font color="#000000">x</font></span><font color="#000066">.</font><span style="background-color: #ffffff"><font color="#000000">str</font></span>=<font color="#0000cc"><i>"Test"</i></font>
        <font color="#000000"><b>call</b></font> <span style="background-color: #ffffff"><font color="#000000">BJDebugMsg</font></span>( <span style="background-color: #ffffff"><font color="#000000">x</font></span>[<font color="#000066">1</font>])
        <font color="#000000"><b>call</b></font> <span style="background-color: #ffffff"><font color="#000000">BJDebugMsg</font></span>( <span style="background-color: #ffffff"><font color="#000000">x</font></span>[<font color="#000066">0</font>]+<span style="background-color: #ffffff"><font color="#000000">x</font></span>[<font color="#000066">3</font>])

        <font color="#000000"><b>set</b></font> <span style="background-color: #ffffff"><font color="#000000">x</font></span>[<font color="#000066">1</font>] = <font color="#0000cc"><i>"."</i></font>
        <font color="#000000"><b>call</b></font> <span style="background-color: #ffffff"><font color="#000000">BJDebugMsg</font></span>( <span style="background-color: #ffffff"><font color="#000000">x</font></span><font color="#000066">.</font><span style="background-color: #ffffff"><font color="#000000">str</font></span>)
    <font color="#000000"><b>endfunction</b></font>


</pre>

<p>By this example we are overloading the [] operator and giving it a new function for the objects of type <i>operatortest</i>. The operator [] specifies the replacement for array get and []= is the replacement for array get.</p>

<p>After inspecting the code you may notice that we are making the string function as an array of strings (or actually characters)</p>

<p>The [] operator requires 1 argument (index), the []= operator requires 2 arguments (index and value to assign). [] must return a value.</p>

<p>[] and []= operators can also be declared as static. This might have some uses, the struct name is going to be allowed to use index operators.</p>

<p>There is a lot of criticism towards operator overloading since it allows programmers to make code that does not make sense, please use this feature with responsibility.</p>

<p>You can also overload &lt; and &gt; , notice that there is only syntax to declare &lt; by declaring it you are forcefully determining an order relation for structs of that type. So it automatically makes &gt; based on your &lt; declaration.</p>

<pre>
    <font color="#000000"><b>struct</b></font> <span style="background-color: #ffffff"><font color="#000000">operatortest</font></span>
        <font color="#7777cc"><b>string</b></font> <span style="background-color: #ffffff"><font color="#000000">str</font></span>=<font color="#0000cc"><i>""</i></font>

        <font color="#000000"><b>method</b></font> <font color="#000000"><b>operator</b></font> [] <font color="#000000"><b>takes</b></font> <font color="#7777cc"><b>integer</b></font> <span style="background-color: #ffffff"><font color="#000000">i</font></span> <font color="#000000"><b>returns</b></font> <font color="#7777cc"><b>string</b></font>
            <font color="#000000"><b>return</b></font> <span style="background-color: #ffffff"><font color="#000000">SubString</font></span>(<font color="#000066">.</font><span style="background-color: #ffffff"><font color="#000000">str</font></span>,<span style="background-color: #ffffff"><font color="#000000">i</font></span>,<span style="background-color: #ffffff"><font color="#000000">i</font></span>+<font color="#000066">1</font>)
        <font color="#000000"><b>endmethod</b></font>

        <font color="#000000"><b>method</b></font> <font color="#000000"><b>operator</b></font>[]= <font color="#000000"><b>takes</b></font> <font color="#7777cc"><b>integer</b></font> <span style="background-color: #ffffff"><font color="#000000">i</font></span>, <font color="#7777cc"><b>string</b></font> <span style="background-color: #ffffff"><font color="#000000">ch</font></span> <font color="#000000"><b>returns</b></font> <font color="#7777cc"><b>nothing</b></font>
            <font color="#000000"><b>set</b></font> <font color="#000066">.</font><span style="background-color: #ffffff"><font color="#000000">str</font></span>=<span style="background-color: #ffffff"><font color="#000000">SubString</font></span>(<font color="#000066">.</font><span style="background-color: #ffffff"><font color="#000000">str</font></span>,<font color="#000066">0</font>,<span style="background-color: #ffffff"><font color="#000000">i</font></span>)+<span style="background-color: #ffffff"><font color="#000000">ch</font></span>+<span style="background-color: #ffffff"><font color="#000000">SubString</font></span>(<font color="#000066">.</font><span style="background-color: #ffffff"><font color="#000000">str</font></span>,<span style="background-color: #ffffff"><font color="#000000">i</font></span>+<font color="#000066">1</font>,<span style="background-color: #ffffff"><font color="#000000">StringLength</font></span>(<font color="#000066">.</font><span style="background-color: #ffffff"><font color="#000000">str</font></span>)-<span style="background-color: #ffffff"><font color="#000000">i</font></span>)
        <font color="#000000"><b>endmethod</b></font>

        <font color="#000000"><b>method</b></font> <font color="#000000"><b>operator</b></font>&lt; <font color="#000000"><b>takes</b></font>  <span style="background-color: #ffffff"><font color="#000000">operatortest</font></span> <span style="background-color: #ffffff"><font color="#000000">b</font></span> <font color="#000000"><b>returns</b></font> <font color="#7777cc"><b>boolean</b></font>
            <font color="#000000"><b>return</b></font> <span style="background-color: #ffffff"><font color="#000000">StringLength</font></span>(<font color="#000066">this</font><font color="#000066">.</font><span style="background-color: #ffffff"><font color="#000000">str</font></span>) &lt; <span style="background-color: #ffffff"><font color="#000000">StringLength</font></span>(<span style="background-color: #ffffff"><font color="#000000">b</font></span><font color="#000066">.</font><span style="background-color: #ffffff"><font color="#000000">str</font></span>)
        <font color="#000000"><b>endmethod</b></font>

    <font color="#000000"><b>endstruct</b></font>


    <font color="#000000"><b>function</b></font> <span style="background-color: #ffffff"><font color="#000000">test</font></span> <font color="#000000"><b>takes</b></font> <font color="#7777cc"><b>nothing</b></font> <font color="#000000"><b>returns</b></font> <font color="#7777cc"><b>nothing</b></font>
     <font color="#000000"><b>local</b></font> <span style="background-color: #ffffff"><font color="#000000">operatortest</font></span> <span style="background-color: #ffffff"><font color="#000000">x</font></span>=<span style="background-color: #ffffff"><font color="#000000">operatortest</font></span><font color="#000066">.</font><span style="background-color: #ffffff"><font color="#000000">create</font></span>()
     <font color="#000000"><b>local</b></font> <span style="background-color: #ffffff"><font color="#000000">operatortest</font></span> <span style="background-color: #ffffff"><font color="#000000">y</font></span>=<span style="background-color: #ffffff"><font color="#000000">operatortest</font></span><font color="#000066">.</font><span style="background-color: #ffffff"><font color="#000000">create</font></span>()

        <font color="#000000"><b>set</b></font> <span style="background-color: #ffffff"><font color="#000000">x</font></span><font color="#000066">.</font><span style="background-color: #ffffff"><font color="#000000">str</font></span>=<font color="#0000cc"><i>"Test..."</i></font>
        <font color="#000000"><b>set</b></font> <span style="background-color: #ffffff"><font color="#000000">y</font></span><font color="#000066">.</font><span style="background-color: #ffffff"><font color="#000000">str</font></span>=<font color="#0000cc"><i>".Test"</i></font>

        <font color="#000000"><b>if</b></font> (<span style="background-color: #ffffff"><font color="#000000">x</font></span>&lt;<span style="background-color: #ffffff"><font color="#000000">y</font></span>) <font color="#000000"><b>then</b></font>
            <font color="#000000"><b>call</b></font> <span style="background-color: #ffffff"><font color="#000000">BJDebugMsg</font></span>(<font color="#0000cc"><i>"Less than"</i></font>)
        <font color="#000000"><b>endif</b></font>
        <font color="#000000"><b>if</b></font> (<span style="background-color: #ffffff"><font color="#000000">x</font></span>&gt;<span style="background-color: #ffffff"><font color="#000000">y</font></span>) <font color="#000000"><b>then</b></font>
            <font color="#000000"><b>call</b></font> <span style="background-color: #ffffff"><font color="#000000">BJDebugMsg</font></span>(<font color="#0000cc"><i>"Greater than"</i></font>)
        <font color="#000000"><b>endif</b></font>
    <font color="#000000"><b>endfunction</b></font>


</pre>

<p>In the example, an object of type operatortest is considered greater than another object of that type if the length of its str member is greater than the length of the other object's str member.</p>

<p>operator&lt; must return a boolean value and take an argument of the same type as the struct.</p>

<p>Operators are interface friendly meaning that an interface may declare operators, there is a catch and it is that the operator&lt; must be declared without signature in an interface. Also when using &gt; or &lt; to compare interface objects both instances must have the same type, otherwise the function would halt before performing the comparisson, if debug mode was enabled when compiling, it will also show a warning message.</p>

<pre>    <font color="#000000"><b>interface</b></font> <span style="background-color: #ffffff"><font color="#000000">ordered</font></span>
        <font color="#000000"><b>method</b></font> <font color="#000000"><b>operator</b></font> &lt;
    <font color="#000000"><b>endinterface</b></font>

    <font color="#000000"><b>interface</b></font> <span style="background-color: #ffffff"><font color="#000000">indexed</font></span>
        <font color="#000000"><b>method</b></font> <font color="#000000"><b>operator</b></font> [] <font color="#000000"><b>takes</b></font> <font color="#7777cc"><b>integer</b></font> <span style="background-color: #ffffff"><font color="#000000">index</font></span> <font color="#000000"><b>returns</b></font> <span style="background-color: #ffffff"><font color="#000000">ordered</font></span>
        <font color="#000000"><b>method</b></font> <font color="#000000"><b>operator</b></font> []= <font color="#000000"><b>takes</b></font> <font color="#7777cc"><b>integer</b></font> <span style="background-color: #ffffff"><font color="#000000">index</font></span>, <span style="background-color: #ffffff"><font color="#000000">ordered</font></span> <span style="background-color: #ffffff"><font color="#000000">v</font></span> <font color="#000000"><b>returns</b></font> <font color="#7777cc"><b>nothing</b></font>
    <font color="#000000"><b>endinterface</b></font>

    <font color="#000000"><b>function</b></font> <span style="background-color: #ffffff"><font color="#000000">sort</font></span> <font color="#000000"><b>takes</b></font> <span style="background-color: #ffffff"><font color="#000000">indexed</font></span> <span style="background-color: #ffffff"><font color="#000000">a</font></span>, <font color="#7777cc"><b>integer</b></font> <span style="background-color: #ffffff"><font color="#000000">from</font></span>, <font color="#7777cc"><b>integer</b></font> <span style="background-color: #ffffff"><font color="#000000">to</font></span> <font color="#000000"><b>returns</b></font> <font color="#7777cc"><b>nothing</b></font>
     <font color="#000000"><b>local</b></font> <font color="#7777cc"><b>integer</b></font> <span style="background-color: #ffffff"><font color="#000000">i</font></span>
     <font color="#000000"><b>local</b></font> <font color="#7777cc"><b>integer</b></font> <span style="background-color: #ffffff"><font color="#000000">j</font></span>
     <font color="#000000"><b>local</b></font> <span style="background-color: #ffffff"><font color="#000000">ordered</font></span> <span style="background-color: #ffffff"><font color="#000000">aux</font></span>

        <font color="#000000"><b>set</b></font> <span style="background-color: #ffffff"><font color="#000000">i</font></span>=<span style="background-color: #ffffff"><font color="#000000">from</font></span>
        <font color="#000000"><b>loop</b></font>
            <font color="#000000"><b>exitwhen</b></font> (<span style="background-color: #ffffff"><font color="#000000">i</font></span>&gt;=<span style="background-color: #ffffff"><font color="#000000">to</font></span>)
            <font color="#000000"><b>set</b></font> <span style="background-color: #ffffff"><font color="#000000">j</font></span>=<span style="background-color: #ffffff"><font color="#000000">i</font></span>+<font color="#000066">1</font>
            <font color="#000000"><b>loop</b></font>
                <font color="#000000"><b>exitwhen</b></font> (<span style="background-color: #ffffff"><font color="#000000">j</font></span>&gt;<span style="background-color: #ffffff"><font color="#000000">to</font></span>)
                <font color="#000000"><b>if</b></font> (<span style="background-color: #ffffff"><font color="#000000">a</font></span>[<span style="background-color: #ffffff"><font color="#000000">j</font></span>]&lt;<span style="background-color: #ffffff"><font color="#000000">a</font></span>[<span style="background-color: #ffffff"><font color="#000000">i</font></span>]) <font color="#000000"><b>then</b></font>
                    <font color="#000000"><b>set</b></font> <span style="background-color: #ffffff"><font color="#000000">aux</font></span> = <span style="background-color: #ffffff"><font color="#000000">a</font></span>[<span style="background-color: #ffffff"><font color="#000000">i</font></span>]
                    <font color="#000000"><b>set</b></font> <span style="background-color: #ffffff"><font color="#000000">a</font></span>[<span style="background-color: #ffffff"><font color="#000000">i</font></span>] = <span style="background-color: #ffffff"><font color="#000000">a</font></span>[<span style="background-color: #ffffff"><font color="#000000">j</font></span>]
                    <font color="#000000"><b>set</b></font> <span style="background-color: #ffffff"><font color="#000000">a</font></span>[<span style="background-color: #ffffff"><font color="#000000">j</font></span>] = <span style="background-color: #ffffff"><font color="#000000">aux</font></span>
                <font color="#000000"><b>endif</b></font>
                <font color="#000000"><b>set</b></font> <span style="background-color: #ffffff"><font color="#000000">j</font></span>=<span style="background-color: #ffffff"><font color="#000000">j</font></span>+<font color="#000066">1</font>
            <font color="#000000"><b>endloop</b></font>

            <font color="#000000"><b>set</b></font> <span style="background-color: #ffffff"><font color="#000000">i</font></span>=<span style="background-color: #ffffff"><font color="#000000">i</font></span>+<font color="#000066">1</font>
        <font color="#000000"><b>endloop</b></font>
    <font color="#000000"><b>endfunction</b></font>

</pre>

<p>This is an interface for a sorting algorithm. We may now declare custom types that work to sort stuff:</p>

<pre>
    <font color="#000000"><b>struct</b></font> <span style="background-color: #ffffff"><font color="#000000">integerpair</font></span> <font color="#000000"><b>extends</b></font> <span style="background-color: #ffffff"><font color="#000000">ordered</font></span>
        <font color="#7777cc"><b>integer</b></font> <span style="background-color: #ffffff"><font color="#000000">x</font></span>
        <font color="#7777cc"><b>integer</b></font> <span style="background-color: #ffffff"><font color="#000000">y</font></span>

        <font color="#000000"><b>method</b></font> <font color="#000000"><b>operator</b></font>&lt; <font color="#000000"><b>takes</b></font> <span style="background-color: #ffffff"><font color="#000000">integerpair</font></span> <span style="background-color: #ffffff"><font color="#000000">b</font></span> <font color="#000000"><b>returns</b></font> <font color="#7777cc"><b>boolean</b></font>
            <font color="#000000"><b>if</b></font> (<span style="background-color: #ffffff"><font color="#000000">b</font></span><font color="#000066">.</font><span style="background-color: #ffffff"><font color="#000000">x</font></span>==<font color="#000066">this</font><font color="#000066">.</font><span style="background-color: #ffffff"><font color="#000000">x</font></span>) <font color="#000000"><b>then</b></font>
                <font color="#000000"><b>return</b></font> (<font color="#000066">this</font><font color="#000066">.</font><span style="background-color: #ffffff"><font color="#000000">y</font></span>&lt;<span style="background-color: #ffffff"><font color="#000000">b</font></span><font color="#000066">.</font><span style="background-color: #ffffff"><font color="#000000">y</font></span>)
            <font color="#000000"><b>endif</b></font>
            <font color="#000000"><b>return</b></font> (<font color="#000066">this</font><font color="#000066">.</font><span style="background-color: #ffffff"><font color="#000000">x</font></span>&lt;<span style="background-color: #ffffff"><font color="#000000">b</font></span><font color="#000066">.</font><span style="background-color: #ffffff"><font color="#000000">x</font></span>)
        <font color="#000000"><b>endmethod</b></font>
    <font color="#000000"><b>endstruct</b></font>

    <font color="#000000"><b>type</b></font> <span style="background-color: #ffffff"><font color="#000000">ipairarray</font></span> <font color="#000000"><b>extends</b></font> <span style="background-color: #ffffff"><font color="#000000">integerpair</font></span> <font color="#7777cc"><b>array</b></font> [<font color="#000066">400</font>]

    <font color="#000000"><b>struct</b></font> <span style="background-color: #ffffff"><font color="#000000">integerpairarray</font></span> <font color="#000000"><b>extends</b></font> <span style="background-color: #ffffff"><font color="#000000">indexed</font></span>
        <span style="background-color: #ffffff"><font color="#000000">ipairarray</font></span> <span style="background-color: #ffffff"><font color="#000000">data</font></span>

        <font color="#000000"><b>method</b></font> <font color="#000000"><b>operator</b></font>[] <font color="#000000"><b>takes</b></font> <font color="#7777cc"><b>integer</b></font> <span style="background-color: #ffffff"><font color="#000000">index</font></span> <font color="#000000"><b>returns</b></font> <span style="background-color: #ffffff"><font color="#000000">ordered</font></span>
            <font color="#000000"><b>return</b></font> <span style="background-color: #ffffff"><font color="#000000">ordered</font></span>( <font color="#000066">this</font><font color="#000066">.</font><span style="background-color: #ffffff"><font color="#000000">data</font></span>[<span style="background-color: #ffffff"><font color="#000000">index</font></span>] )
        <font color="#000000"><b>endmethod</b></font>

        <font color="#000000"><b>method</b></font> <font color="#000000"><b>operator</b></font>[]= <font color="#000000"><b>takes</b></font> <font color="#7777cc"><b>integer</b></font> <span style="background-color: #ffffff"><font color="#000000">index</font></span>, <span style="background-color: #ffffff"><font color="#000000">ordered</font></span> <span style="background-color: #ffffff"><font color="#000000">value</font></span> <font color="#000000"><b>returns</b></font> <font color="#7777cc"><b>nothing</b></font>
            <font color="#000000"><b>set</b></font> <font color="#000066">this</font><font color="#000066">.</font><span style="background-color: #ffffff"><font color="#000000">data</font></span>[<span style="background-color: #ffffff"><font color="#000000">index</font></span>] = <span style="background-color: #ffffff"><font color="#000000">integerpair</font></span>( <span style="background-color: #ffffff"><font color="#000000">value</font></span>)
        <font color="#000000"><b>endmethod</b></font>
    <font color="#000000"><b>endstruct</b></font>

</pre>

<p>Of course, it is just an example, the logical way would be using quicksort, operators are also good since they would also allow textmacros to use them, the same sorting textmacro might then be compatible with integer, real and any struct with overloaded &lt; operator.</p>

<p>You may also declare a custom ==, works same as &lt; if you declare this operator, != will be translated to not(your method). Also, notice that to do pointer comparisons you will need to use integer(var1)==integer(var2)</p>

<h5 style="color: black">More things we can do with custom operators</h5>

<p>One thing is to <i>overload</i> [], &gt;, &lt;, you can also make a method mimic a field, to keep abstraction and simplify syntax.</p>

<pre><font color="#000000"><b>struct</b></font> <span style="background-color: #ffffff"><font color="#000000">X</font></span>
    <font color="#7777cc"><b>integer</b></font> <span style="background-color: #ffffff"><font color="#000000">a</font></span>=<font color="#000066">2</font>
    <font color="#7777cc"><b>integer</b></font> <span style="background-color: #ffffff"><font color="#000000">b</font></span>=<font color="#000066">2</font>

    <font color="#000000"><b>method</b></font> <font color="#000000"><b>operator</b></font> <span style="background-color: #ffffff"><font color="#000000">x</font></span> <font color="#000000"><b>takes</b></font> <font color="#7777cc"><b>nothing</b></font> <font color="#000000"><b>returns</b></font> <font color="#7777cc"><b>integer</b></font>
        <font color="#000000"><b>return</b></font> <font color="#000066">this</font><font color="#000066">.</font><span style="background-color: #ffffff"><font color="#000000">a</font></span>*<font color="#000066">this</font><font color="#000066">.</font><span style="background-color: #ffffff"><font color="#000000">b</font></span>
    <font color="#000000"><b>endmethod</b></font>

    <font color="#000000"><b>method</b></font> <font color="#000000"><b>operator</b></font> <span style="background-color: #ffffff"><font color="#000000">x</font></span>= <font color="#000000"><b>takes</b></font> <font color="#7777cc"><b>integer</b></font> <span style="background-color: #ffffff"><font color="#000000">v</font></span> <font color="#000000"><b>returns</b></font> <font color="#7777cc"><b>nothing</b></font>
        <font color="#000000"><b>set</b></font> <font color="#000066">this</font><font color="#000066">.</font><span style="background-color: #ffffff"><font color="#000000">a</font></span>=<span style="background-color: #ffffff"><font color="#000000">v</font></span>/<font color="#000066">this</font><font color="#000066">.</font><span style="background-color: #ffffff"><font color="#000000">b</font></span>
    <font color="#000000"><b>endmethod</b></font>


<font color="#000000"><b>endstruct</b></font>



<font color="#000000"><b>function</b></font> <span style="background-color: #ffffff"><font color="#000000">test</font></span> <font color="#000000"><b>takes</b></font> <font color="#7777cc"><b>nothing</b></font> <font color="#000000"><b>returns</b></font> <font color="#7777cc"><b>nothing</b></font>
 <font color="#000000"><b>local</b></font> <span style="background-color: #ffffff"><font color="#000000">X</font></span> <span style="background-color: #ffffff"><font color="#000000">obj</font></span>= <span style="background-color: #ffffff"><font color="#000000">X</font></span><font color="#000066">.</font><span style="background-color: #ffffff"><font color="#000000">create</font></span>()

    <font color="#000000"><b>set</b></font> <span style="background-color: #ffffff"><font color="#000000">obj</font></span><font color="#000066">.</font><span style="background-color: #ffffff"><font color="#000000">x</font></span>= <span style="background-color: #ffffff"><font color="#000000">obj</font></span><font color="#000066">.</font><span style="background-color: #ffffff"><font color="#000000">x</font></span> + <font color="#000066">4</font>

    <font color="#000000"><b>call</b></font> <span style="background-color: #ffffff"><font color="#000000">BJDebugMsg</font></span>(<span style="background-color: #ffffff"><font color="#000000">I2S</font></span>( <span style="background-color: #ffffff"><font color="#000000">obj</font></span><font color="#000066">.</font><span style="background-color: #ffffff"><font color="#000000">x</font></span>) ) <font color="#008800">//outputs 8</font>
    <font color="#000000"><b>set</b></font> <span style="background-color: #ffffff"><font color="#000000">obj</font></span><font color="#000066">.</font><span style="background-color: #ffffff"><font color="#000000">b</font></span>=<font color="#000066">4</font>

    <font color="#000000"><b>call</b></font> <span style="background-color: #ffffff"><font color="#000000">BJDebugMsg</font></span>(<span style="background-color: #ffffff"><font color="#000000">I2S</font></span>( <span style="background-color: #ffffff"><font color="#000000">obj</font></span><font color="#000066">.</font><span style="background-color: #ffffff"><font color="#000000">x</font></span>) ) <font color="#008800">//outputs 16</font>

<font color="#000000"><b>endfunction</b></font>
</pre>

<p>You can use this to implement read only fields:</p>

<pre><font color="#000000"><b>struct</b></font> <span style="background-color: #ffffff"><font color="#000000">X</font></span>
    <font color="#000000"><b>private</b></font> <font color="#7777cc"><b>integer</b></font> <span style="background-color: #ffffff"><font color="#000000">va</font></span>=<font color="#000066">2</font>

    <font color="#000000"><b>method</b></font> <font color="#000000"><b>operator</b></font> <span style="background-color: #ffffff"><font color="#000000">a</font></span> <font color="#000000"><b>takes</b></font> <font color="#7777cc"><b>nothing</b></font> <font color="#000000"><b>returns</b></font> <font color="#7777cc"><b>integer</b></font>
        <font color="#000000"><b>return</b></font> <font color="#000066">this</font><font color="#000066">.</font><span style="background-color: #ffffff"><font color="#000000">a</font></span>
    <font color="#000000"><b>endmethod</b></font>

<font color="#000000"><b>endstruct</b></font>



<font color="#000000"><b>function</b></font> <span style="background-color: #ffffff"><font color="#000000">test</font></span> <font color="#000000"><b>takes</b></font> <font color="#7777cc"><b>nothing</b></font> <font color="#000000"><b>returns</b></font> <font color="#7777cc"><b>nothing</b></font>
 <font color="#000000"><b>local</b></font> <span style="background-color: #ffffff"><font color="#000000">X</font></span> <span style="background-color: #ffffff"><font color="#000000">obj</font></span>= <span style="background-color: #ffffff"><font color="#000000">X</font></span><font color="#000066">.</font><span style="background-color: #ffffff"><font color="#000000">create</font></span>()

    <font color="#000000"><b>call</b></font> <span style="background-color: #ffffff"><font color="#000000">BJDebugMsg</font></span>(<span style="background-color: #ffffff"><font color="#000000">I2S</font></span>( <span style="background-color: #ffffff"><font color="#000000">obj</font></span><font color="#000066">.</font><span style="background-color: #ffffff"><font color="#000000">a</font></span>) ) <font color="#008800">//This is legal</font>

    <font color="#000000"><b>set</b></font> <span style="background-color: #ffffff"><font color="#000000">obj</font></span><font color="#000066">.</font><span style="background-color: #ffffff"><font color="#000000">a</font></span>=<font color="#000066">2</font> <font color="#008800">//this is not</font>

<font color="#000000"><b>endfunction</b></font>
</pre>

<p>More importantly, you can use it to implement fields that take extra provisions for assigments:</p>

<pre><font color="#000000"><b>struct</b></font> <span style="background-color: #ffffff"><font color="#000000">movableEffect</font></span>

    <font color="#000000"><b>private</b></font> <font color="#7777cc"><b>unit</b></font> <span style="background-color: #ffffff"><font color="#000000">dummy</font></span>
    <font color="#000000"><b>private</b></font> <font color="#7777cc"><b>string</b></font> <span style="background-color: #ffffff"><font color="#000000">rfx</font></span>
    <font color="#000000"><b>private</b></font> <font color="#7777cc"><b>effect</b></font> <span style="background-color: #ffffff"><font color="#000000">uniteffect</font></span>

    <font color="#008800">//...</font>
        <font color="#008800">//(A lot of code implementing other actions and creation)</font>
    <font color="#008800">//...</font>

    <font color="#000000"><b>method</b></font> <font color="#000000"><b>operator</b></font> <span style="background-color: #ffffff"><font color="#000000">x</font></span> <font color="#000000"><b>takes</b></font> <font color="#7777cc"><b>nothing</b></font> <font color="#000000"><b>returns</b></font> <font color="#7777cc"><b>real</b></font>
        <font color="#000000"><b>return</b></font> <span style="background-color: #ffffff"><font color="#000000">GetUnitX</font></span>(<font color="#000066">this</font><font color="#000066">.</font><span style="background-color: #ffffff"><font color="#000000">dummy</font></span>)
    <font color="#000000"><b>endmethod</b></font>

    <font color="#000000"><b>method</b></font> <font color="#000000"><b>operator</b></font> <span style="background-color: #ffffff"><font color="#000000">y</font></span> <font color="#000000"><b>takes</b></font> <font color="#7777cc"><b>nothing</b></font> <font color="#000000"><b>returns</b></font> <font color="#7777cc"><b>real</b></font>
        <font color="#000000"><b>return</b></font> <span style="background-color: #ffffff"><font color="#000000">GetUnitY</font></span>(<font color="#000066">this</font><font color="#000066">.</font><span style="background-color: #ffffff"><font color="#000000">dummy</font></span>)
    <font color="#000000"><b>endmethod</b></font>

    <font color="#000000"><b>method</b></font> <font color="#000000"><b>operator</b></font> <span style="background-color: #ffffff"><font color="#000000">x</font></span>= <font color="#000000"><b>takes</b></font> <font color="#7777cc"><b>real</b></font> <span style="background-color: #ffffff"><font color="#000000">value</font></span> <font color="#000000"><b>returns</b></font> <font color="#7777cc"><b>nothing</b></font>
        <font color="#000000"><b>call</b></font> <span style="background-color: #ffffff"><font color="#000000">SetUnitX</font></span>(<font color="#000066">this</font><font color="#000066">.</font><span style="background-color: #ffffff"><font color="#000000">dummy</font></span>, <span style="background-color: #ffffff"><font color="#000000">value</font></span>)
    <font color="#000000"><b>endmethod</b></font>

    <font color="#000000"><b>method</b></font> <font color="#000000"><b>operator</b></font> <span style="background-color: #ffffff"><font color="#000000">y</font></span>= <font color="#000000"><b>takes</b></font> <font color="#7777cc"><b>real</b></font> <span style="background-color: #ffffff"><font color="#000000">value</font></span> <font color="#000000"><b>returns</b></font> <font color="#7777cc"><b>nothing</b></font>
        <font color="#000000"><b>call</b></font> <span style="background-color: #ffffff"><font color="#000000">SetUnitY</font></span>(<font color="#000066">this</font><font color="#000066">.</font><span style="background-color: #ffffff"><font color="#000000">dummy</font></span>, <span style="background-color: #ffffff"><font color="#000000">value</font></span>)
    <font color="#000000"><b>endmethod</b></font>


    <font color="#000000"><b>method</b></font> <font color="#000000"><b>operator</b></font> <span style="background-color: #ffffff"><font color="#000000">effectpath</font></span> <font color="#000000"><b>takes</b></font> <font color="#7777cc"><b>nothing</b></font> <font color="#000000"><b>returns</b></font> <font color="#7777cc"><b>string</b></font>
        <font color="#000000"><b>return</b></font> <font color="#000066">this</font><font color="#000066">.</font><span style="background-color: #ffffff"><font color="#000000">rfx</font></span>
    <font color="#000000"><b>endmethod</b></font>

    <font color="#000000"><b>method</b></font> <font color="#000000"><b>operator</b></font> <span style="background-color: #ffffff"><font color="#000000">effectpath=</font></span> <font color="#000000"><b>takes</b></font> <font color="#7777cc"><b>string</b></font> <span style="background-color: #ffffff"><font color="#000000">path</font></span> <font color="#000000"><b>returns</b></font> <font color="#7777cc"><b>nothing</b></font>
        <font color="#000000"><b>set</b></font> <font color="#000066">this</font><font color="#000066">.</font><span style="background-color: #ffffff"><font color="#000000">rfx</font></span>=<span style="background-color: #ffffff"><font color="#000000">path</font></span>
        <font color="#000000"><b>call</b></font> <span style="background-color: #ffffff"><font color="#000000">DestroyEffect</font></span>( <font color="#000066">this</font><font color="#000066">.</font><span style="background-color: #ffffff"><font color="#000000">uniteffect</font></span>)
        <font color="#000000"><b>set</b></font> <font color="#000066">this</font><font color="#000066">.</font><span style="background-color: #ffffff"><font color="#000000">uniteffect</font></span> = <span style="background-color: #ffffff"><font color="#000000">AddSpecialEffectTarget</font></span>(<font color="#000066">this</font><font color="#000066">.</font><span style="background-color: #ffffff"><font color="#000000">dummy</font></span>, <span style="background-color: #ffffff"><font color="#000000">path</font></span>, <font color="#0000cc"><i>"origin"</i></font>)
    <font color="#000000"><b>endmethod</b></font>

<font color="#000000"><b>endstruct</b></font>


<font color="#000000"><b>function</b></font> <span style="background-color: #ffffff"><font color="#000000">moveRandom</font></span> <font color="#000000"><b>takes</b></font> <span style="background-color: #ffffff"><font color="#000000">movableEffect</font></span> <span style="background-color: #ffffff"><font color="#000000">me</font></span> <font color="#000000"><b>returns</b></font> <font color="#7777cc"><b>nothing</b></font>
    <font color="#000000"><b>set</b></font> <span style="background-color: #ffffff"><font color="#000000">me</font></span><font color="#000066">.</font><span style="background-color: #ffffff"><font color="#000000">x</font></span>= <span style="background-color: #ffffff"><font color="#000000">me</font></span><font color="#000066">.</font><span style="background-color: #ffffff"><font color="#000000">x</font></span> + <span style="background-color: #ffffff"><font color="#000000">GetRandomReal</font></span>(-<font color="#000066">50</font>,<font color="#000066">50</font>)
    <font color="#000000"><b>set</b></font> <span style="background-color: #ffffff"><font color="#000000">me</font></span><font color="#000066">.</font><span style="background-color: #ffffff"><font color="#000000">y</font></span>= <span style="background-color: #ffffff"><font color="#000000">me</font></span><font color="#000066">.</font><span style="background-color: #ffffff"><font color="#000000">y</font></span> + <span style="background-color: #ffffff"><font color="#000000">GetRandomReal</font></span>(-<font color="#000066">50</font>,<font color="#000066">50</font>)
<font color="#000000"><b>endfunction</b></font>

<font color="#000000"><b>function</b></font> <span style="background-color: #ffffff"><font color="#000000">toFire</font></span> <font color="#000000"><b>takes</b></font> <span style="background-color: #ffffff"><font color="#000000">movableEffect</font></span> <span style="background-color: #ffffff"><font color="#000000">me</font></span> <font color="#000000"><b>returns</b></font> <font color="#7777cc"><b>nothing</b></font>
    <font color="#000000"><b>set</b></font> <span style="background-color: #ffffff"><font color="#000000">me</font></span><font color="#000066">.</font><span style="background-color: #ffffff"><font color="#000000">effectpath</font></span> =<font color="#0000cc"><i>"war3mapimporte\\cutefireeffect.mdl"</i></font>
<font color="#000000"><b>endfunction</b></font>
</pre>

<p><b>Hint:</b> With operators like .fieldname= and []= it is possible to have a return value in the method, however this return value would almost always be impossible to get from outside the function, there is an exception, and it is when these methods return a value of the struct's type, then it will get translated to an assignment. For example, instead of call var_set(object,45), the result would be set object=var_set(object,45)</p>

<p><b>Note:</b> Since 0.9.Z.1, this syntax is also supported for static members.</p>

<h3 style="color: black"><a name="extendstruct"></a>Extending structs</h3>

<p>It is possible to base an struct from a previously declared struct, by doing this your new type is going to acquire methods and variable members of the base struct, it is also able to use instances of this type with functions and variables of the base type.</p>

<p>Consider doing this as a way to add code and properties to a previous type.</p>

<pre><font color="#000000"><b>struct</b></font> <span style="background-color: #ffffff"><font color="#000000">A</font></span>
   <font color="#0055aa"><b>integer</b></font> <span style="background-color: #ffffff"><font color="#000000">x</font></span>
   <font color="#0055aa"><b>integer</b></font> <span style="background-color: #ffffff"><font color="#000000">y</font></span>

   <font color="#000000"><b>method</b></font> <span style="background-color: #ffffff"><font color="#000000">setxy</font></span> <font color="#000000"><b>takes</b></font> <font color="#0055aa"><b>integer</b></font> <span style="background-color: #ffffff"><font color="#000000">cx</font></span>, <font color="#0055aa"><b>integer</b></font> <span style="background-color: #ffffff"><font color="#000000">cy</font></span> <font color="#000000"><b>returns</b></font> <font color="#0055aa"><b>nothing</b></font>
       <font color="#000000"><b>set</b></font> <font color="#0000aa">this</font><font color="#0000aa">.</font><span style="background-color: #ffffff"><font color="#000000">x</font></span>=<span style="background-color: #ffffff"><font color="#000000">cx</font></span>
       <font color="#000000"><b>set</b></font> <font color="#0000aa">this</font><font color="#0000aa">.</font><span style="background-color: #ffffff"><font color="#000000">y</font></span>=<span style="background-color: #ffffff"><font color="#000000">cy</font></span>
   <font color="#000000"><b>endmethod</b></font>
<font color="#000000"><b>endstruct</b></font>

<font color="#000000"><b>struct</b></font> <span style="background-color: #ffffff"><font color="#000000">B</font></span> <font color="#000000"><b>extends</b></font> <span style="background-color: #ffffff"><font color="#000000">A</font></span>
   <font color="#0055aa"><b>integer</b></font> <span style="background-color: #ffffff"><font color="#000000">z</font></span>
   <font color="#000000"><b>method</b></font> <span style="background-color: #ffffff"><font color="#000000">setxyz</font></span> <font color="#000000"><b>takes</b></font> <font color="#0055aa"><b>integer</b></font> <span style="background-color: #ffffff"><font color="#000000">cx</font></span>, <font color="#0055aa"><b>integer</b></font> <span style="background-color: #ffffff"><font color="#000000">cy</font></span>, <font color="#0055aa"><b>integer</b></font> <span style="background-color: #ffffff"><font color="#000000">cz</font></span> <font color="#000000"><b>returns</b></font> <font color="#0055aa"><b>nothing</b></font>
       <font color="#000000"><b>call</b></font> <font color="#0000aa">this</font><font color="#0000aa">.</font><span style="background-color: #ffffff"><font color="#000000">setxy</font></span>(<span style="background-color: #ffffff"><font color="#000000">cx</font></span>,<span style="background-color: #ffffff"><font color="#000000">cy</font></span>) <font color="#008800">//we can use A's members</font>
       <font color="#000000"><b>set</b></font> <font color="#0000aa">this</font><font color="#0000aa">.</font><span style="background-color: #ffffff"><font color="#000000">z</font></span>=<span style="background-color: #ffffff"><font color="#000000">cz</font></span>
   <font color="#000000"><b>endmethod</b></font>
<font color="#000000"><b>endstruct</b></font>
</pre>

<p>Internally, B.allocate() is actually calling A's constructor and B.destroy will also call B's deconstructor. If a base struct got a custom create method, the structs extending it will have to use it for allocate(). If the custom create method requires arguments, the allocate method for child structs will require the same arguments:</p>

<pre><font color="#000000"><b>struct</b></font> <span style="background-color: #ffffff"><font color="#000000">A</font></span>
   <font color="#0055aa"><b>integer</b></font> <span style="background-color: #ffffff"><font color="#000000">x</font></span>
   <font color="#000000"><b>static</b></font> <font color="#000000"><b>method</b></font> <span style="background-color: #ffffff"><font color="#000000">create</font></span> <font color="#000000"><b>takes</b></font> <font color="#0055aa"><b>integer</b></font> <span style="background-color: #ffffff"><font color="#000000">k</font></span> <font color="#000000"><b>returns</b></font> <span style="background-color: #ffffff"><font color="#000000">A</font></span>
    <font color="#000000"><b>local</b></font> <span style="background-color: #ffffff"><font color="#000000">A</font></span> <span style="background-color: #ffffff"><font color="#000000">s</font></span>=<span style="background-color: #ffffff"><font color="#000000">A</font></span><font color="#0000aa">.</font><span style="background-color: #ffffff"><font color="#000000">allocate</font></span>()
       <font color="#000000"><b>set</b></font> <span style="background-color: #ffffff"><font color="#000000">A</font></span><font color="#0000aa">.</font><span style="background-color: #ffffff"><font color="#000000">x</font></span>=<span style="background-color: #ffffff"><font color="#000000">k</font></span>
    <font color="#000000"><b>return</b></font> <span style="background-color: #ffffff"><font color="#000000">s</font></span>
   <font color="#000000"><b>endmethod</b></font>
<font color="#000000"><b>endstruct</b></font>

<font color="#000000"><b>struct</b></font> <span style="background-color: #ffffff"><font color="#000000">B</font></span> <font color="#000000"><b>extends</b></font> <span style="background-color: #ffffff"><font color="#000000">A</font></span>
    <font color="#000000"><b>static</b></font> <font color="#000000"><b>method</b></font> <span style="background-color: #ffffff"><font color="#000000">create</font></span> <font color="#000000"><b>takes</b></font> <font color="#0055aa"><b>nothing</b></font> <font color="#000000"><b>returns</b></font> <span style="background-color: #ffffff"><font color="#000000">B</font></span>
        <font color="#000000"><b>return</b></font> <span style="background-color: #ffffff"><font color="#000000">s</font></span>= <span style="background-color: #ffffff"><font color="#000000">B</font></span><font color="#0000aa">.</font><span style="background-color: #ffffff"><font color="#000000">allocate</font></span>(<font color="#0000aa">445</font>)  <font color="#008800">//notice that B.allocate requires the same arguments as A.create()</font>
    <font color="#000000"><b>endmethod</b></font>
<font color="#000000"><b>endstruct</b></font>

<font color="#000000"><b>struct</b></font> <span style="background-color: #ffffff"><font color="#000000">C</font></span> <font color="#000000"><b>extends</b></font> <span style="background-color: #ffffff"><font color="#000000">B</font></span> <font color="#008800">//yep, it is possible to extend an struct that is extending another one</font>
    <font color="#000000"><b>static</b></font> <font color="#000000"><b>method</b></font> <span style="background-color: #ffffff"><font color="#000000">create</font></span> <font color="#000000"><b>takes</b></font> <font color="#0055aa"><b>nothing</b></font> <font color="#000000"><b>returns</b></font> <span style="background-color: #ffffff"><font color="#000000">B</font></span>
     <font color="#000000"><b>local</b></font> <span style="background-color: #ffffff"><font color="#000000">C</font></span> <span style="background-color: #ffffff"><font color="#000000">s</font></span>=<span style="background-color: #ffffff"><font color="#000000">C</font></span><font color="#0000aa">.</font><span style="background-color: #ffffff"><font color="#000000">allocate</font></span>() <font color="#008800">//C is a child of B that got a custom create method that takes nothing, so allocate takes nothing as well.</font>
       <font color="#000000"><b>set</b></font> <span style="background-color: #ffffff"><font color="#000000">s</font></span><font color="#0000aa">.</font><span style="background-color: #ffffff"><font color="#000000">x</font></span>=<span style="background-color: #ffffff"><font color="#000000">s</font></span><font color="#0000aa">.</font><span style="background-color: #ffffff"><font color="#000000">x</font></span>*<span style="background-color: #ffffff"><font color="#000000">s</font></span><font color="#0000aa">.</font><span style="background-color: #ffffff"><font color="#000000">x</font></span> <font color="#008800">//once again reusing the parents' members.</font>
     <font color="#000000"><b>return</b></font> <span style="background-color: #ffffff"><font color="#000000">s</font></span>
    <font color="#000000"><b>endmethod</b></font>
<font color="#000000"><b>endstruct</b></font>
</pre>

<p>If an struct has declared create to be private, it is impossible to extend it. Structs cannot use private members from parent structs.</p>

<p>The behaviour of the onDestroy method is special in this case, if in the last example, A,B and C had an onDestroy method each, destroying an instance of a C would call C.onDestroy(), B.onDestroy() and A.onDestroy() (in that order)</p>

<p>It is possible to extend an struct that extends an interface, in this case, the child that extends the interface directly is forced to implement the interface's methods, but its childs are not. But it is possible for them to replace them again.</p>

<pre><font color="#000000"><b>interface</b></font> <span style="background-color: #ffffff"><font color="#000000">myinterface</font></span>
   <font color="#000000"><b>method</b></font> <span style="background-color: #ffffff"><font color="#000000">processunit</font></span> <font color="#000000"><b>takes</b></font> <font color="#0055aa"><b>unit</b></font> <span style="background-color: #ffffff"><font color="#000000">u</font></span> <font color="#000000"><b>returns</b></font> <font color="#0055aa"><b>nothing</b></font>
   <font color="#000000"><b>method</b></font> <span style="background-color: #ffffff"><font color="#000000">onAnEvent</font></span> <font color="#000000"><b>takes</b></font> <font color="#0055aa"><b>nothing</b></font> <font color="#000000"><b>returns</b></font> <font color="#0055aa"><b>boolean</b></font>
<font color="#000000"><b>endinterface</b></font>

<font color="#000000"><b>struct</b></font> <span style="background-color: #ffffff"><font color="#000000">A</font></span> <font color="#000000"><b>extends</b></font> <span style="background-color: #ffffff"><font color="#000000">myinterface</font></span>

   <font color="#000000"><b>method</b></font> <span style="background-color: #ffffff"><font color="#000000">processunit</font></span> <font color="#000000"><b>takes</b></font> <font color="#0055aa"><b>unit</b></font> <span style="background-color: #ffffff"><font color="#000000">u</font></span> <font color="#000000"><b>returns</b></font> <font color="#0055aa"><b>nothing</b></font>
       <font color="#000000"><b>call</b></font> <span style="background-color: #ffffff"><font color="#000000">KillUnit</font></span>(<span style="background-color: #ffffff"><font color="#000000">u</font></span>)
   <font color="#000000"><b>endmethod</b></font>

   <font color="#000000"><b>method</b></font> <span style="background-color: #ffffff"><font color="#000000">onAnEvent</font></span> <font color="#000000"><b>takes</b></font> <font color="#0055aa"><b>nothing</b></font> <font color="#000000"><b>returns</b></font> <font color="#0055aa"><b>boolean</b></font>
       <font color="#000000"><b>return</b></font> <font color="#0000aa">false</font>
   <font color="#000000"><b>endmethod</b></font>
<font color="#000000"><b>endstruct</b></font>

<font color="#000000"><b>struct</b></font> <span style="background-color: #ffffff"><font color="#000000">B</font></span> <font color="#000000"><b>extends</b></font> <span style="background-color: #ffffff"><font color="#000000">A</font></span>

   <font color="#000000"><b>method</b></font> <span style="background-color: #ffffff"><font color="#000000">processunit</font></span> <font color="#000000"><b>takes</b></font> <font color="#0055aa"><b>unit</b></font> <span style="background-color: #ffffff"><font color="#000000">u</font></span> <font color="#000000"><b>returns</b></font> <font color="#0055aa"><b>nothing</b></font>
      <font color="#008800">//we have just replaced A&amp;apos;s processunit method,</font>
      <font color="#008800">//if an interface variable of type myinterface holds an instance of </font>
      <font color="#008800">//type B it will explode the unit.</font>
      <font color="#000000"><b>call</b></font> <span style="background-color: #ffffff"><font color="#000000">ExplodeUnitBJ</font></span>(<span style="background-color: #ffffff"><font color="#000000">u</font></span>)
   <font color="#000000"><b>endmethod</b></font>
   <font color="#008800">// we are implementing processunit but we do not have to implement onAnEvent   </font>

<font color="#000000"><b>endstruct</b></font>

</pre>

<p>If you plan using interface.create() you will have to be careful once again about constructors with arguments, if an interface is declared with the condition that create takes nothing every child (,grandchild, etc) of the interface will be affected by this condition.</p>

<h3 style="color: black"><a name="stubmeth"></a>Stub methods</h3>

<p>stub methods can simply be rewriten by child structs. An example should help:</p>
<font face="monospace"><font color="#000000"><b>struct</b></font>&nbsp;<span style="background-color: #ffffff"><font color="#000000">Parent</font></span><br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;<font color="#000000"><b>stub</b></font>&nbsp;<font color="#000000"><b>method</b></font>&nbsp;<span style="background-color: #ffffff"><font color="#000000">xx</font></span>&nbsp;<font color="#000000"><b>takes</b></font>&nbsp;<font color="#7777cc"><b>nothing</b></font>&nbsp;<font color="#000000"><b>returns</b></font>&nbsp;<font color="#7777cc"><b>nothing</b></font><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#000000"><b>call</b></font>&nbsp;<span style="background-color: #ffffff"><font color="#000000">BJDebugMsg</font></span>(<font color="#0000cc"><i>"Parent"</i></font>)<br>
&nbsp;&nbsp;&nbsp;&nbsp;<font color="#000000"><b>endmethod</b></font><br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;<font color="#000000"><b>method</b></font>&nbsp;<span style="background-color: #ffffff"><font color="#000000">doSomething</font></span>&nbsp;<font color="#000000"><b>takes</b></font>&nbsp;<font color="#7777cc"><b>nothing</b></font>&nbsp;<font color="#000000"><b>returns</b></font>&nbsp;<font color="#7777cc"><b>nothing</b></font><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#000000"><b>call</b></font>&nbsp;<font color="#000066">this</font><font color="#000066">.</font><span style="background-color: #ffffff"><font color="#000000">xx</font></span>()<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#000000"><b>call</b></font>&nbsp;<font color="#000066">this</font><font color="#000066">.</font><span style="background-color: #ffffff"><font color="#000000">xx</font></span>()<br>
&nbsp;&nbsp;&nbsp;&nbsp;<font color="#000000"><b>endmethod</b></font><br>
<br>
<font color="#000000"><b>endstruct</b></font><br>
<br>
<font color="#000000"><b>struct</b></font>&nbsp;<span style="background-color: #ffffff"><font color="#000000">ChildA</font></span>&nbsp;<font color="#000000"><b>extends</b></font>&nbsp;<span style="background-color: #ffffff"><font color="#000000">Parent</font></span><br>
&nbsp;&nbsp;&nbsp;&nbsp;<font color="#000000"><b>method</b></font>&nbsp;<span style="background-color: #ffffff"><font color="#000000">xx</font></span>&nbsp;<font color="#000000"><b>takes</b></font>&nbsp;<font color="#7777cc"><b>nothing</b></font>&nbsp;<font color="#000000"><b>returns</b></font>&nbsp;<font color="#7777cc"><b>nothing</b></font><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#000000"><b>call</b></font>&nbsp;<span style="background-color: #ffffff"><font color="#000000">BJDebugMsg</font></span>(<font color="#0000cc"><i>"- Child A -"</i></font>)<br>
&nbsp;&nbsp;&nbsp;&nbsp;<font color="#000000"><b>endmethod</b></font><br>
<font color="#000000"><b>endstruct</b></font><br>
<br>
<font color="#000000"><b>struct</b></font>&nbsp;<span style="background-color: #ffffff"><font color="#000000">ChildB</font></span>&nbsp;<font color="#000000"><b>extends</b></font>&nbsp;<span style="background-color: #ffffff"><font color="#000000">Parent</font></span><br>
&nbsp;&nbsp;&nbsp;&nbsp;<font color="#000000"><b>method</b></font>&nbsp;<span style="background-color: #ffffff"><font color="#000000">xx</font></span>&nbsp;<font color="#000000"><b>takes</b></font>&nbsp;<font color="#7777cc"><b>nothing</b></font>&nbsp;<font color="#000000"><b>returns</b></font>&nbsp;<font color="#7777cc"><b>nothing</b></font><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#000000"><b>call</b></font>&nbsp;<span style="background-color: #ffffff"><font color="#000000">BJDebugMsg</font></span>(<font color="#0000cc"><i>"- Child B --"</i></font>)<br>
&nbsp;&nbsp;&nbsp;&nbsp;<font color="#000000"><b>endmethod</b></font><br>
<font color="#000000"><b>endstruct</b></font><br>
<br>
<br>
<font color="#000000"><b>function</b></font>&nbsp;<span style="background-color: #ffffff"><font color="#000000">test</font></span>&nbsp;<font color="#000000"><b>takes</b></font>&nbsp;<font color="#7777cc"><b>nothing</b></font>&nbsp;<font color="#000000"><b>returns</b></font>&nbsp;<font color="#7777cc"><b>nothing</b></font><br>
&nbsp;<font color="#000000"><b>local</b></font>&nbsp;<span style="background-color: #ffffff"><font color="#000000">Parent</font></span>&nbsp;<span style="background-color: #ffffff"><font color="#000000">P</font></span>&nbsp;= <span style="background-color: #ffffff"><font color="#000000">Parent</font></span><font color="#000066">.</font><span style="background-color: #ffffff"><font color="#000000">create</font></span>()<br>
&nbsp;<font color="#000000"><b>local</b></font>&nbsp;<span style="background-color: #ffffff"><font color="#000000">Parent</font></span>&nbsp;<span style="background-color: #ffffff"><font color="#000000">A</font></span>&nbsp;= <span style="background-color: #ffffff"><font color="#000000">ChildA</font></span><font color="#000066">.</font><span style="background-color: #ffffff"><font color="#000000">create</font></span>()<br>
&nbsp;<font color="#000000"><b>local</b></font>&nbsp;<span style="background-color: #ffffff"><font color="#000000">Parent</font></span>&nbsp;<span style="background-color: #ffffff"><font color="#000000">B</font></span>&nbsp;= <span style="background-color: #ffffff"><font color="#000000">ChildB</font></span><font color="#000066">.</font><span style="background-color: #ffffff"><font color="#000000">create</font></span>()<br>
&nbsp;&nbsp;&nbsp;&nbsp;<font color="#008800">//notice the variables are of the 'Parent' type.</font><br>
&nbsp;&nbsp;&nbsp;&nbsp;<font color="#000000"><b>call</b></font>&nbsp;<span style="background-color: #ffffff"><font color="#000000">P</font></span><font color="#000066">.</font><span style="background-color: #ffffff"><font color="#000000">doSomething</font></span>() <font color="#008800">//Shows 'Parent' twice</font><br>
&nbsp;&nbsp;&nbsp;&nbsp;<font color="#000000"><b>call</b></font>&nbsp;<span style="background-color: #ffffff"><font color="#000000">A</font></span><font color="#000066">.</font><span style="background-color: #ffffff"><font color="#000000">doSomething</font></span>() <font color="#008800">//Shows 'Child A' twice</font><br>
&nbsp;&nbsp;&nbsp;&nbsp;<font color="#000000"><b>call</b></font>&nbsp;<span style="background-color: #ffffff"><font color="#000000">B</font></span><font color="#000066">.</font><span style="background-color: #ffffff"><font color="#000000">doSomething</font></span>() <font color="#008800">//Shows 'Child B' twice</font><br>
<font color="#000000"><b>endfunction</b></font></font><br>
&nbsp;
<p>Just notice there are differences between these and interfaces, first of all, interfaces require you to make the methods. They also allow the .exists().</p>

<h3 style="color: black"><a name="super"></a>super</h3>

<p>When you are extending another struct, it could happen that the struct is extending an interface, or that the method you are coding is replacing a stub method. What happens if you want to call the parent's version of the method? It is not possible without specifying that you want to do it. (Else it will end up calling the child's method instead).</p>

<p><strong>super</strong> is meant to allow that, it works in the same way as this, but it forces the parent's method to be called:</p>
<font face="monospace"> <font color="#000000"><b>struct</b></font>&nbsp;<span style="background-color: #ffffff"><font color="#000000">Parent</font></span><br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;<font color="#000000"><b>stub</b></font>&nbsp;<font color="#000000"><b>method</b></font>&nbsp;<span style="background-color: #ffffff"><font color="#000000">xx</font></span>&nbsp;<font color="#000000"><b>takes</b></font>&nbsp;<font color="#7777cc"><b>nothing</b></font>&nbsp;<font color="#000000"><b>returns</b></font>&nbsp;<font color="#7777cc"><b>nothing</b></font><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#000000"><b>call</b></font>&nbsp;<span style="background-color: #ffffff"><font color="#000000">BJDebugMsg</font></span>(<font color="#0000cc"><i>"Parent"</i></font>)<br>
&nbsp;&nbsp;&nbsp;&nbsp;<font color="#000000"><b>endmethod</b></font><br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;<font color="#000000"><b>method</b></font>&nbsp;<span style="background-color: #ffffff"><font color="#000000">doSomething</font></span>&nbsp;<font color="#000000"><b>takes</b></font>&nbsp;<font color="#7777cc"><b>nothing</b></font>&nbsp;<font color="#000000"><b>returns</b></font>&nbsp;<font color="#7777cc"><b>nothing</b></font><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#000000"><b>call</b></font>&nbsp;<font color="#000066">this</font><font color="#000066">.</font><span style="background-color: #ffffff"><font color="#000000">xx</font></span>()<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#000000"><b>call</b></font>&nbsp;<font color="#000066">this</font><font color="#000066">.</font><span style="background-color: #ffffff"><font color="#000000">xx</font></span>()<br>
&nbsp;&nbsp;&nbsp;&nbsp;<font color="#000000"><b>endmethod</b></font><br>
<br>
<font color="#000000"><b>endstruct</b></font><br>
<br>
<font color="#000000"><b>struct</b></font>&nbsp;<span style="background-color: #ffffff"><font color="#000000">ChildA</font></span>&nbsp;<font color="#000000"><b>extends</b></font>&nbsp;<span style="background-color: #ffffff"><font color="#000000">Parent</font></span><br>
&nbsp;&nbsp;&nbsp;&nbsp;<font color="#000000"><b>method</b></font>&nbsp;<span style="background-color: #ffffff"><font color="#000000">xx</font></span>&nbsp;<font color="#000000"><b>takes</b></font>&nbsp;<font color="#7777cc"><b>nothing</b></font>&nbsp;<font color="#000000"><b>returns</b></font>&nbsp;<font color="#7777cc"><b>nothing</b></font><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#000000"><b>call</b></font>&nbsp;<span style="background-color: #ffffff"><font color="#000000">BJDebugMsg</font></span>(<font color="#0000cc"><i>"- Child A -"</i></font>)<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#000000"><b>call</b></font>&nbsp;<span style="background-color: #ffffff"><font color="#000000">super</font></span><font color="#000066">.</font><span style="background-color: #ffffff"><font color="#000000">xx</font></span>()<br>
&nbsp;&nbsp;&nbsp;&nbsp;<font color="#000000"><b>endmethod</b></font><br>
<font color="#000000"><b>endstruct</b></font><br>
<br>
<font color="#000000"><b>struct</b></font>&nbsp;<span style="background-color: #ffffff"><font color="#000000">ChildB</font></span>&nbsp;<font color="#000000"><b>extends</b></font>&nbsp;<span style="background-color: #ffffff"><font color="#000000">Parent</font></span><br>
&nbsp;&nbsp;&nbsp;&nbsp;<font color="#000000"><b>method</b></font>&nbsp;<span style="background-color: #ffffff"><font color="#000000">xx</font></span>&nbsp;<font color="#000000"><b>takes</b></font>&nbsp;<font color="#7777cc"><b>nothing</b></font>&nbsp;<font color="#000000"><b>returns</b></font>&nbsp;<font color="#7777cc"><b>nothing</b></font><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#000000"><b>call</b></font>&nbsp;<span style="background-color: #ffffff"><font color="#000000">BJDebugMsg</font></span>(<font color="#0000cc"><i>"- Child B --"</i></font>)<br>
&nbsp;&nbsp;&nbsp;&nbsp;<font color="#000000"><b>endmethod</b></font><br>
<font color="#000000"><b>endstruct</b></font><br>
<br>
<br>
<font color="#000000"><b>function</b></font>&nbsp;<span style="background-color: #ffffff"><font color="#000000">test</font></span>&nbsp;<font color="#000000"><b>takes</b></font>&nbsp;<font color="#7777cc"><b>nothing</b></font>&nbsp;<font color="#000000"><b>returns</b></font>&nbsp;<font color="#7777cc"><b>nothing</b></font><br>
&nbsp;<font color="#000000"><b>local</b></font>&nbsp;<span style="background-color: #ffffff"><font color="#000000">Parent</font></span>&nbsp;<span style="background-color: #ffffff"><font color="#000000">P</font></span>&nbsp;= <span style="background-color: #ffffff"><font color="#000000">Parent</font></span><font color="#000066">.</font><span style="background-color: #ffffff"><font color="#000000">create</font></span>()<br>
&nbsp;<font color="#000000"><b>local</b></font>&nbsp;<span style="background-color: #ffffff"><font color="#000000">Parent</font></span>&nbsp;<span style="background-color: #ffffff"><font color="#000000">A</font></span>&nbsp;= <span style="background-color: #ffffff"><font color="#000000">ChildA</font></span><font color="#000066">.</font><span style="background-color: #ffffff"><font color="#000000">create</font></span>()<br>
&nbsp;<font color="#000000"><b>local</b></font>&nbsp;<span style="background-color: #ffffff"><font color="#000000">Parent</font></span>&nbsp;<span style="background-color: #ffffff"><font color="#000000">B</font></span>&nbsp;= <span style="background-color: #ffffff"><font color="#000000">ChildB</font></span><font color="#000066">.</font><span style="background-color: #ffffff"><font color="#000000">create</font></span>()<br>
&nbsp;&nbsp;&nbsp;&nbsp;<font color="#008800">//notice the variables are of the 'Parent' type.</font><br>
&nbsp;&nbsp;&nbsp;&nbsp;<font color="#000000"><b>call</b></font>&nbsp;<span style="background-color: #ffffff"><font color="#000000">P</font></span><font color="#000066">.</font><span style="background-color: #ffffff"><font color="#000000">doSomething</font></span>() <font color="#008800">//Shows 'Parent' twice</font><br>
&nbsp;&nbsp;&nbsp;&nbsp;<font color="#000000"><b>call</b></font>&nbsp;<span style="background-color: #ffffff"><font color="#000000">A</font></span><font color="#000066">.</font><span style="background-color: #ffffff"><font color="#000000">doSomething</font></span>() <font color="#008800">//Shows 'Child A|nParent' twice</font><br>
&nbsp;&nbsp;&nbsp;&nbsp;<font color="#000000"><b>call</b></font>&nbsp;<span style="background-color: #ffffff"><font color="#000000">B</font></span><font color="#000066">.</font><span style="background-color: #ffffff"><font color="#000000">doSomething</font></span>() <font color="#008800">//Shows 'Child B' twice</font><br>
<font color="#000000"><b>endfunction</b></font></font><br>
&nbsp;
<h3 style="color: black"><a name="dynarr"></a>Dynamic arrays</h3>

<p>Dynamic arrays are arrays you can instanciate dynamically, EACH custom array type has got a limit of 8190 TOTAL indexes, that means that an array type of size 100 has got an 81 instances limit.</p>

<p>They are kind of easy to declare and use, and somehow share syntax with structs.</p>

<p>You simply make a line outside any function/struct declaration: type &lt;nameoftype&gt; extends &lt;nameofbasetype&gt; array [ &lt;size&gt;] Where size is an integer value or constant global.</p>

<p>Then you can simply create/usem them in a similar way to structs and use the [] operator to access its indexes, dynamic arrays have also got an static size constant</p>

<pre><font color="#000000"><b>type</b></font> <span style="background-color: #ffffff"><font color="#000000">arsample</font></span> <font color="#000000"><b>extends</b></font> <font color="#7777cc"><b>integer</b></font> <font color="#7777cc"><b>array</b></font>[<font color="#000066">8</font>]

<font color="#000000"><b>function</b></font> <span style="background-color: #ffffff"><font color="#000000">test</font></span> <font color="#000000"><b>takes</b></font> <font color="#7777cc"><b>nothing</b></font> <font color="#000000"><b>returns</b></font> <span style="background-color: #ffffff"><font color="#000000">arsample</font></span>
 <font color="#000000"><b>local</b></font> <span style="background-color: #ffffff"><font color="#000000">arsample</font></span> <span style="background-color: #ffffff"><font color="#000000">r</font></span>=<span style="background-color: #ffffff"><font color="#000000">arsample</font></span><font color="#000066">.</font><span style="background-color: #ffffff"><font color="#000000">create</font></span>()
 <font color="#000000"><b>local</b></font> <font color="#7777cc"><b>integer</b></font> <span style="background-color: #ffffff"><font color="#000000">i</font></span>=<font color="#000066">0</font>
     <font color="#000000"><b>loop</b></font>
         <font color="#000000"><b>exitwhen</b></font> <span style="background-color: #ffffff"><font color="#000000">i</font></span>==<span style="background-color: #ffffff"><font color="#000000">arsample</font></span><font color="#000066">.</font><span style="background-color: #ffffff"><font color="#000000">size</font></span> <font color="#008800">//holds size of the array type</font>
         <font color="#000000"><b>set</b></font> <span style="background-color: #ffffff"><font color="#000000">r</font></span>[<span style="background-color: #ffffff"><font color="#000000">i</font></span>]=<span style="background-color: #ffffff"><font color="#000000">i</font></span>
         <font color="#000000"><b>set</b></font> <span style="background-color: #ffffff"><font color="#000000">i</font></span>=<span style="background-color: #ffffff"><font color="#000000">i</font></span>+<font color="#000066">1</font>
     <font color="#000000"><b>endloop</b></font>
 <font color="#000000"><b>return</b></font> <span style="background-color: #ffffff"><font color="#000000">r</font></span>
<font color="#000000"><b>endfunction</b></font>

<font color="#000000"><b>function</b></font> <span style="background-color: #ffffff"><font color="#000000">test2</font></span> <font color="#000000"><b>takes</b></font> <font color="#7777cc"><b>nothing</b></font> <font color="#000000"><b>returns</b></font> <span style="background-color: #ffffff"><font color="#000000">arsample</font></span>
 <font color="#000000"><b>local</b></font> <span style="background-color: #ffffff"><font color="#000000">arsample</font></span> <span style="background-color: #ffffff"><font color="#000000">r</font></span>=<span style="background-color: #ffffff"><font color="#000000">test</font></span>()
 <font color="#000000"><b>local</b></font> <font color="#7777cc"><b>integer</b></font> <span style="background-color: #ffffff"><font color="#000000">i</font></span>=<font color="#000066">0</font>
     <font color="#000000"><b>loop</b></font>
         <font color="#000000"><b>exitwhen</b></font> <span style="background-color: #ffffff"><font color="#000000">i</font></span>==<span style="background-color: #ffffff"><font color="#000000">arsample</font></span><font color="#000066">.</font><span style="background-color: #ffffff"><font color="#000000">size</font></span>
         <font color="#000000"><b>call</b></font> <span style="background-color: #ffffff"><font color="#000000">BJDebugMsg</font></span>(<span style="background-color: #ffffff"><font color="#000000">I2S</font></span>(<span style="background-color: #ffffff"><font color="#000000">r</font></span>[<span style="background-color: #ffffff"><font color="#000000">i</font></span>]))
         <font color="#000000"><b>set</b></font> <span style="background-color: #ffffff"><font color="#000000">i</font></span>=<span style="background-color: #ffffff"><font color="#000000">i</font></span>+<font color="#000066">1</font>
     <font color="#000000"><b>endloop</b></font>
 <font color="#000000"><b>return</b></font> <span style="background-color: #ffffff"><font color="#000000">r</font></span>
<font color="#000000"><b>endfunction</b></font>
</pre>

<p>You can extend arrays of any type, even of custom types (structs, interfaces, other dynamic arrays) thus making a dynamic array of dynamic arrays, a matrix like syntax is possible:</p>

<pre><font color="#000000"><b>type</b></font> <span style="background-color: #ffffff"><font color="#000000">iar</font></span> <font color="#000000"><b>extends</b></font> <font color="#7777cc"><b>integer</b></font> <font color="#7777cc"><b>array</b></font>[<font color="#000066">3</font>]
<font color="#000000"><b>type</b></font> <span style="background-color: #ffffff"><font color="#000000">iar_ar</font></span> <font color="#000000"><b>extends</b></font> <span style="background-color: #ffffff"><font color="#000000">iar</font></span> <font color="#7777cc"><b>array</b></font>[<font color="#000066">3</font>]

<font color="#000000"><b>function</b></font> <span style="background-color: #ffffff"><font color="#000000">test</font></span> <font color="#000000"><b>takes</b></font> <font color="#7777cc"><b>nothing</b></font> <font color="#000000"><b>returns</b></font> <span style="background-color: #ffffff"><font color="#000000">arsample</font></span>
 <font color="#000000"><b>local</b></font> <span style="background-color: #ffffff"><font color="#000000">iar_ar</font></span> <span style="background-color: #ffffff"><font color="#000000">r</font></span>=<span style="background-color: #ffffff"><font color="#000000">iar_ar</font></span><font color="#000066">.</font><span style="background-color: #ffffff"><font color="#000000">create</font></span>()
 <font color="#000000"><b>local</b></font> <font color="#7777cc"><b>integer</b></font> <span style="background-color: #ffffff"><font color="#000000">i</font></span>=<font color="#000066">0</font>
 <font color="#000000"><b>local</b></font> <font color="#7777cc"><b>integer</b></font> <span style="background-color: #ffffff"><font color="#000000">j</font></span>
     <font color="#000000"><b>loop</b></font>
         <font color="#000000"><b>exitwhen</b></font> <span style="background-color: #ffffff"><font color="#000000">i</font></span>==<span style="background-color: #ffffff"><font color="#000000">iar_ar</font></span><font color="#000066">.</font><span style="background-color: #ffffff"><font color="#000000">size</font></span> <font color="#008800">//holds size of the array type</font>
         <font color="#000000"><b>set</b></font> <span style="background-color: #ffffff"><font color="#000000">r</font></span>[<span style="background-color: #ffffff"><font color="#000000">i</font></span>]=<span style="background-color: #ffffff"><font color="#000000">iar</font></span><font color="#000066">.</font><span style="background-color: #ffffff"><font color="#000000">create</font></span>()
         <font color="#000000"><b>set</b></font> <span style="background-color: #ffffff"><font color="#000000">j</font></span>=<font color="#000066">0</font>
         <font color="#000000"><b>loop</b></font>
             <font color="#000000"><b>exitwhen</b></font> <span style="background-color: #ffffff"><font color="#000000">j</font></span>==<span style="background-color: #ffffff"><font color="#000000">iar</font></span><font color="#000066">.</font><span style="background-color: #ffffff"><font color="#000000">size</font></span>
             <font color="#000000"><b>set</b></font> <span style="background-color: #ffffff"><font color="#000000">r</font></span>[<span style="background-color: #ffffff"><font color="#000000">i</font></span>][<span style="background-color: #ffffff"><font color="#000000">j</font></span>]=<span style="background-color: #ffffff"><font color="#000000">j</font></span>*<span style="background-color: #ffffff"><font color="#000000">i</font></span>
             <font color="#000000"><b>set</b></font> <span style="background-color: #ffffff"><font color="#000000">j</font></span>=<span style="background-color: #ffffff"><font color="#000000">j</font></span>+<font color="#000066">1</font>
         <font color="#000000"><b>endloop</b></font>

         <font color="#000000"><b>set</b></font> <span style="background-color: #ffffff"><font color="#000000">i</font></span>=<span style="background-color: #ffffff"><font color="#000000">i</font></span>+<font color="#000066">1</font>
     <font color="#000000"><b>endloop</b></font>
 <font color="#000000"><b>return</b></font> <span style="background-color: #ffffff"><font color="#000000">r</font></span>
<font color="#000000"><b>endfunction</b></font>


</pre>

<p>And structs may have these arrays as members thus allowing array members for instances (non-static)</p>

<pre>
<font color="#000000"><b>type</b></font> <span style="background-color: #ffffff"><font color="#000000">stackarray</font></span> <font color="#000000"><b>extends</b></font> <font color="#7777cc"><b>integer</b></font> <font color="#7777cc"><b>array</b></font> [<font color="#000066">20</font>]

<font color="#000000"><b>struct</b></font> <span style="background-color: #ffffff"><font color="#000000">stack</font></span>
   <font color="#000000"><b>private</b></font> <span style="background-color: #ffffff"><font color="#000000">stackarray</font></span> <span style="background-color: #ffffff"><font color="#000000">V</font></span>
   <font color="#000000"><b>private</b></font> <font color="#7777cc"><b>integer</b></font> <span style="background-color: #ffffff"><font color="#000000">N</font></span>=<font color="#000066">0</font>

   <font color="#000000"><b>method</b></font> <span style="background-color: #ffffff"><font color="#000000">Create</font></span> <font color="#000000"><b>takes</b></font> <font color="#7777cc"><b>nothing</b></font> <font color="#000000"><b>returns</b></font> <span style="background-color: #ffffff"><font color="#000000">stack</font></span>
    <font color="#000000"><b>local</b></font> <span style="background-color: #ffffff"><font color="#000000">stack</font></span> <span style="background-color: #ffffff"><font color="#000000">s</font></span>=<span style="background-color: #ffffff"><font color="#000000">stack</font></span><font color="#000066">.</font><span style="background-color: #ffffff"><font color="#000000">create</font></span>()
       <font color="#000000"><b>set</b></font> <span style="background-color: #ffffff"><font color="#000000">s</font></span><font color="#000066">.</font><span style="background-color: #ffffff"><font color="#000000">V</font></span>=<span style="background-color: #ffffff"><font color="#000000">stackarray</font></span><font color="#000066">.</font><span style="background-color: #ffffff"><font color="#000000">create</font></span>()
       <font color="#000000"><b>if</b></font> (<span style="background-color: #ffffff"><font color="#000000">s</font></span><font color="#000066">.</font><span style="background-color: #ffffff"><font color="#000000">V</font></span>==<font color="#000066">0</font>) <font color="#000000"><b>then</b></font>
           <font color="#666666">debug</font> <font color="#000000"><b>call</b></font> <span style="background-color: #ffffff"><font color="#000000">BJDebugMsg</font></span>(<font color="#0000cc"><i>"Warning: not enough space for stack array"</i></font>)
           <font color="#000000"><b>return</b></font> <font color="#000066">0</font>
       <font color="#000000"><b>endif</b></font>
   <font color="#000000"><b>endmethod</b></font>

   <font color="#000000"><b>method</b></font> <span style="background-color: #ffffff"><font color="#000000">push</font></span> <font color="#000000"><b>takes</b></font> <font color="#7777cc"><b>integer</b></font> <span style="background-color: #ffffff"><font color="#000000">i</font></span> <font color="#000000"><b>returns</b></font> <font color="#7777cc"><b>nothing</b></font>
       <font color="#000000"><b>if</b></font> (<font color="#000066">this</font><font color="#000066">.</font><span style="background-color: #ffffff"><font color="#000000">N</font></span>==<span style="background-color: #ffffff"><font color="#000000">stackarray</font></span><font color="#000066">.</font><span style="background-color: #ffffff"><font color="#000000">size</font></span>) <font color="#000000"><b>then</b></font>
           <font color="#666666">debug</font> <font color="#000000"><b>call</b></font> <span style="background-color: #ffffff"><font color="#000000">BJDebugMsg</font></span>(<font color="#0000cc"><i>"Warning: stack is full"</i></font>)
       <font color="#000000"><b>else</b></font>
           <font color="#000000"><b>set</b></font> <font color="#000066">this</font><font color="#000066">.</font><span style="background-color: #ffffff"><font color="#000000">V</font></span>[<font color="#000066">this</font><font color="#000066">.</font><span style="background-color: #ffffff"><font color="#000000">N</font></span>]=<span style="background-color: #ffffff"><font color="#000000">i</font></span>
           <font color="#000000"><b>set</b></font> <font color="#000066">.</font><span style="background-color: #ffffff"><font color="#000000">N</font></span> = <font color="#000066">.</font><span style="background-color: #ffffff"><font color="#000000">N</font></span> +<font color="#000066">1</font> <font color="#008800">//remember this syntax is valid as well</font>
       <font color="#000000"><b>endif</b></font>
   <font color="#000000"><b>endmethod</b></font>

   <font color="#000000"><b>method</b></font> <span style="background-color: #ffffff"><font color="#000000">pop</font></span> <font color="#000000"><b>takes</b></font> <font color="#7777cc"><b>nothing</b></font> <font color="#000000"><b>returns</b></font> <font color="#7777cc"><b>nothing</b></font>
       <font color="#000000"><b>if</b></font> (<font color="#000066">this</font><font color="#000066">.</font><span style="background-color: #ffffff"><font color="#000000">N</font></span>&gt;<font color="#000066">0</font>) <font color="#000000"><b>then</b></font>
           <font color="#000000"><b>set</b></font> <font color="#000066">this</font><font color="#000066">.</font><span style="background-color: #ffffff"><font color="#000000">N</font></span>=<font color="#000066">this</font><font color="#000066">.</font><span style="background-color: #ffffff"><font color="#000000">N</font></span>-<font color="#000066">1</font>
       <font color="#000000"><b>else</b></font>
           <font color="#666666">debug</font> <font color="#000000"><b>call</b></font> <span style="background-color: #ffffff"><font color="#000000">BJDebugMsg</font></span>(<font color="#0000cc"><i>"Warning: attempt to pop an empty stack"</i></font>);
       <font color="#000000"><b>endif</b></font>
   <font color="#000000"><b>endmethod</b></font>

   <font color="#000000"><b>method</b></font> <span style="background-color: #ffffff"><font color="#000000">top</font></span> <font color="#000000"><b>takes</b></font> <font color="#7777cc"><b>nothing</b></font> <font color="#000000"><b>returns</b></font> <font color="#7777cc"><b>integer</b></font>
       <font color="#000000"><b>return</b></font> <font color="#000066">.</font><span style="background-color: #ffffff"><font color="#000000">V</font></span><font color="#000066">[.</font><span style="background-color: #ffffff"><font color="#000000">N</font></span>-<font color="#000066">1</font>]
   <font color="#000000"><b>endmethod</b></font>

   <font color="#000000"><b>method</b></font> <span style="background-color: #ffffff"><font color="#000000">empty</font></span> <font color="#000000"><b>takes</b></font> <font color="#7777cc"><b>nothing</b></font> <font color="#000000"><b>returns</b></font> <font color="#7777cc"><b>boolean</b></font>
       <font color="#000000"><b>return</b></font> (<font color="#000066">.</font><span style="background-color: #ffffff"><font color="#000000">N</font></span>==<font color="#000066">0</font>)
   <font color="#000000"><b>endmethod</b></font>

   <font color="#000000"><b>method</b></font> <span style="background-color: #ffffff"><font color="#000000">onDestroy</font></span> <font color="#000000"><b>takes</b></font> <font color="#7777cc"><b>nothing</b></font> <font color="#000000"><b>returns</b></font> <font color="#7777cc"><b>nothing</b></font>
       <font color="#000000"><b>call</b></font> <font color="#000066">this</font><font color="#000066">.</font><span style="background-color: #ffffff"><font color="#000000">V</font></span><font color="#000066">.</font><span style="background-color: #ffffff"><font color="#000000">destroy</font></span>()
   <font color="#000000"><b>endmethod</b></font>
<font color="#000000"><b>endstruct</b></font>
</pre>

<p>As you may notice, if there is no space for a new instance, the create method of arrays returns 0. It will also warn you automatically if compiled in debug mode</p>

<p>Dynamic arrays got the .size member that allows you to easily access the size you used to declare the array type.</p>

<h3 style="color: black"><a name="arrmemb"></a>Array members</h3>

<p>Structs may have array members but you also require to declare the size of them.</p>

<pre><font color="#000000"><b>struct</b></font> <span style="background-color: #ffffff"><font color="#000000">stack</font></span>
   <font color="#000000"><b>private</b></font> <font color="#7777cc"><b>integer</b></font> <font color="#7777cc"><b>array</b></font> <span style="background-color: #ffffff"><font color="#000000">V</font></span>[<font color="#000066">100</font>]
   <font color="#000000"><b>private</b></font> <font color="#7777cc"><b>integer</b></font> <span style="background-color: #ffffff"><font color="#000000">N</font></span>=<font color="#000066">0</font>

   <font color="#000000"><b>method</b></font> <span style="background-color: #ffffff"><font color="#000000">push</font></span> <font color="#000000"><b>takes</b></font> <font color="#7777cc"><b>integer</b></font> <span style="background-color: #ffffff"><font color="#000000">i</font></span> <font color="#000000"><b>returns</b></font> <font color="#7777cc"><b>nothing</b></font>
      <font color="#000000"><b>set</b></font> <font color="#000066">.</font><span style="background-color: #ffffff"><font color="#000000">V</font></span><font color="#000066">[.</font><span style="background-color: #ffffff"><font color="#000000">N</font></span>]=<span style="background-color: #ffffff"><font color="#000000">i</font></span>
      <font color="#000000"><b>set</b></font> <font color="#000066">.</font><span style="background-color: #ffffff"><font color="#000000">N</font></span><font color="#000066">=.</font><span style="background-color: #ffffff"><font color="#000000">N</font></span>+<font color="#000066">1</font>
   <font color="#000000"><b>endmethod</b></font>

   <font color="#000000"><b>method</b></font> <span style="background-color: #ffffff"><font color="#000000">pop</font></span> <font color="#000000"><b>takes</b></font> <font color="#7777cc"><b>nothing</b></font> <font color="#000000"><b>returns</b></font> <font color="#7777cc"><b>nothing</b></font>
      <font color="#000000"><b>set</b></font> <font color="#000066">.</font><span style="background-color: #ffffff"><font color="#000000">N</font></span><font color="#000066">=.</font><span style="background-color: #ffffff"><font color="#000000">N</font></span>-<font color="#000066">1</font>
   <font color="#000000"><b>endmethod</b></font>

   <font color="#000000"><b>method</b></font> <span style="background-color: #ffffff"><font color="#000000">top</font></span> <font color="#000000"><b>takes</b></font> <font color="#7777cc"><b>nothing</b></font> <font color="#000000"><b>returns</b></font> <font color="#7777cc"><b>integer</b></font>
      <font color="#000000"><b>return</b></font> <font color="#000066">.</font><span style="background-color: #ffffff"><font color="#000000">V</font></span><font color="#000066">[.</font><span style="background-color: #ffffff"><font color="#000000">N</font></span>-<font color="#000066">1</font>]
   <font color="#000000"><b>endmethod</b></font>

   <font color="#000000"><b>method</b></font> <span style="background-color: #ffffff"><font color="#000000">empty</font></span> <font color="#000000"><b>takes</b></font> <font color="#7777cc"><b>nothing</b></font> <font color="#000000"><b>returns</b></font> <font color="#7777cc"><b>boolean</b></font>
      <font color="#000000"><b>return</b></font> (<font color="#000066">.</font><span style="background-color: #ffffff"><font color="#000000">N</font></span>==<font color="#000066">0</font>)
   <font color="#000000"><b>endmethod</b></font>

   <font color="#000000"><b>method</b></font> <span style="background-color: #ffffff"><font color="#000000">full</font></span> <font color="#000000"><b>takes</b></font> <font color="#7777cc"><b>nothing</b></font> <font color="#000000"><b>returns</b></font> <font color="#7777cc"><b>boolean</b></font>
      <font color="#000000"><b>return</b></font> (<font color="#000066">.</font><span style="background-color: #ffffff"><font color="#000000">N</font></span><font color="#000066">==.</font><span style="background-color: #ffffff"><font color="#000000">V</font></span><font color="#000066">.</font><span style="background-color: #ffffff"><font color="#000000">size</font></span>)
   <font color="#000000"><b>endmethod</b></font>

<font color="#000000"><b>endstruct</b></font>

</pre>

<p>In some way, this is syntax candy for declaring a new array type and making it a member of the struct, but this way is a little more optimizer and handles the array allocation/deallocation for you, with the exchange of some limitations.</p>

<p>Notice that this drastically reduces the instances limit of an struct type, for example, we can only have 80 instances (8190 div 100) of the above declared stack object.</p>

<p>An struct may have as many array members as you can type, notice that the array with the maximum size is the one considered when setting the instances limit, so if an struct has 2 array members, one of size 4 and one of size 100, the struct will have a limit of 80 instances.</p>

<p>The disadvantage of this method over declaring the dynamic array type separatedly is that you have less freedom in what concerns assigning to the member another array you create in other occation and things like that... The advantage is that it is faster and takes less code.</p>

<p>As dynamic arrays, array members may also use the .size field.</p>

<h3 style="color: black"><a name="delegat"></a>Delegate</h3>

<p>So far, we've seen many things, interfaces, structs extending other structs, operators, dynamic arrays. You might be asking yourself, is it possible he would add <i>another</i> way to confuse me like heck? Do not despair! Delegate is the answer.</p>

<p><b>delegate</b> is a strange feature, a delegate is just a member of the struct that does stuff for it. The struct just delegates the work to another object, in this case, work would mean 'methods'. It would appear as pointless or just an abbreviation, however it can be very useful and a interesting alternative to extends. The whole delegate idea is in use in some other languages, just notice that Jass is not very dynamic and vJass does inherit a lot of its flaws. For the better or the worse, delegation is a completely compile-time deal in the case of vJass.</p>

<p>A delegate does the struct's job, that is a very simple way to put it, a more complicated way would be, that during compile, if jasshelper cannot find a certain requested member of method, it will begin to look up for that member in the struct's delegates, if it finds this member in one of the delegates it will then compile it as a call to the delegate's member instead.</p>
<font face="monospace"> <font color="#008800">//Array structs are hard to explain, but should be simple to understand with an example</font><br>
<br>
<font color="#000000"><b>struct</b></font>&nbsp;<span style="background-color: #ffffff"><font color="#000000">A</font></span><br>
&nbsp;&nbsp;&nbsp;&nbsp;<font color="#000000"><b>private</b></font>&nbsp;<font color="#7777cc"><b>real</b></font>&nbsp;<span style="background-color: #ffffff"><font color="#000000">x</font></span><br>
&nbsp;&nbsp;&nbsp;&nbsp;<font color="#000000"><b>private</b></font>&nbsp;<font color="#7777cc"><b>real</b></font>&nbsp;<span style="background-color: #ffffff"><font color="#000000">y</font></span><br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;<font color="#000000"><b>public</b></font>&nbsp;<font color="#000000"><b>method</b></font>&nbsp;<span style="background-color: #ffffff"><font color="#000000">performAction</font></span>&nbsp;<font color="#000000"><b>takes</b></font>&nbsp;<font color="#7777cc"><b>nothing</b></font>&nbsp;<font color="#000000"><b>returns</b></font>&nbsp;<font color="#7777cc"><b>nothing</b></font><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#000000"><b>call</b></font>&nbsp;<span style="background-color: #ffffff"><font color="#000000">DestroyEffect</font></span>( <span style="background-color: #ffffff"><font color="#000000">AddSpecialEffect</font></span>(<font color="#0000cc"><i>"path\\model.mdl"</i></font>, <font color="#000066">this</font><font color="#000066">.</font><span style="background-color: #ffffff"><font color="#000000">x</font></span>, <font color="#000066">this</font><font color="#000066">.</font><span style="background-color: #ffffff"><font color="#000000">y</font></span>) )<br>
&nbsp;&nbsp;&nbsp;&nbsp;<font color="#000000"><b>endmethod</b></font><br>
<br>
<font color="#000000"><b>endstruct</b></font><br>
<br>
<font color="#000000"><b>struct</b></font>&nbsp;<span style="background-color: #ffffff"><font color="#000000">B</font></span><br>
&nbsp;&nbsp;&nbsp;&nbsp;<font color="#000000"><b>delegate</b></font>&nbsp;<span style="background-color: #ffffff"><font color="#000000">A</font></span>&nbsp;<span style="background-color: #ffffff"><font color="#000000">deleg</font></span><br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;<font color="#000000"><b>static</b></font>&nbsp;<font color="#000000"><b>method</b></font>&nbsp;<span style="background-color: #ffffff"><font color="#000000">create</font></span>&nbsp;<font color="#000000"><b>takes</b></font>&nbsp;<font color="#7777cc"><b>nothing</b></font>&nbsp;<font color="#000000"><b>returns</b></font>&nbsp;<span style="background-color: #ffffff"><font color="#000000">B</font></span><br>
&nbsp;&nbsp;&nbsp;&nbsp; <font color="#000000"><b>local</b></font>&nbsp;<span style="background-color: #ffffff"><font color="#000000">B</font></span>&nbsp;<span style="background-color: #ffffff"><font color="#000000">b</font></span>&nbsp;= <span style="background-color: #ffffff"><font color="#000000">B</font></span><font color="#000066">.</font><span style="background-color: #ffffff"><font color="#000000">allocate</font></span>()<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#000000"><b>set</b></font>&nbsp;<span style="background-color: #ffffff"><font color="#000000">B</font></span><font color="#000066">.</font><span style="background-color: #ffffff"><font color="#000000">deleg</font></span>&nbsp;= <span style="background-color: #ffffff"><font color="#000000">A</font></span><font color="#000066">.</font><span style="background-color: #ffffff"><font color="#000000">create</font></span>()<br>
&nbsp;&nbsp;&nbsp;&nbsp;<font color="#000000"><b>endmethod</b></font><br>
<br>
<font color="#000000"><b>endstruct</b></font><br>
<br>
<font color="#000000"><b>function</b></font>&nbsp;<span style="background-color: #ffffff"><font color="#000000">testsomething</font></span>&nbsp;<font color="#000000"><b>takes</b></font>&nbsp;<font color="#7777cc"><b>nothing</b></font>&nbsp;<font color="#000000"><b>returns</b></font>&nbsp;<font color="#7777cc"><b>nothing</b></font><br>
&nbsp;<font color="#000000"><b>local</b></font>&nbsp;<span style="background-color: #ffffff"><font color="#000000">B</font></span>&nbsp;<span style="background-color: #ffffff"><font color="#000000">myB</font></span>&nbsp;= <span style="background-color: #ffffff"><font color="#000000">B</font></span><font color="#000066">.</font><span style="background-color: #ffffff"><font color="#000000">create</font></span>()<br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;<font color="#000000"><b>call</b></font>&nbsp;<span style="background-color: #ffffff"><font color="#000000">myB</font></span><font color="#000066">.</font><span style="background-color: #ffffff"><font color="#000000">performAction</font></span>()<br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;<font color="#008800">//Since performAction() is not a member of struct B, jasshelper will check out the</font><br>
&nbsp;&nbsp;&nbsp;&nbsp;<font color="#008800">//delegator, it does have a method called performAction, so it will just try to call</font><br>
&nbsp;&nbsp;&nbsp;&nbsp;<font color="#008800">//it, the result would be the same as:</font><br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;<font color="#000000"><b>call</b></font>&nbsp;<span style="background-color: #ffffff"><font color="#000000">myB</font></span><font color="#000066">.</font><span style="background-color: #ffffff"><font color="#000000">deleg</font></span><font color="#000066">.</font><span style="background-color: #ffffff"><font color="#000000">performAction</font></span>()<br>
<br>
<font color="#000000"><b>endfunction</b></font></font><br>
&nbsp;
<p>Some considerations:</p>

<ul>
	<li>You can have multiple delegates, however that should probably be the exception rather than the rule.</li>
	<li>jasshelper gives priority to the struct's members before its delegates' this means that if both the struct and a delegate have the same member, jasshelper will always consider the struct's over the delegate's.</li>
	<li>Between delegates in the same struct, the priorities are the same as the declaration order.</li>
	<li>You can do a lot of quacky things like delegating to an array member, you will even be able to use .size() and [] on the struct in that case.</li>
	<li>You can also do non-sense as making a integer member a delegate, this will not cause a syntax error but does not really do much by itself, considering that integers have no members.</li>
	<li>Right now, you cannot make a delegate's method fulfill a interface's rules, for example if struct B was extending a certain interface that required a method called performAction, jasshelper would not recognize the delegate's method and will cause a syntax error, this might change in the future.
	<p></p>
	</li>
	<li>You would usually have to initialize the delegate if you do not want bugs in your code.</li>
	<li>You can have a private delegate, it would only be accessible by outside code in cases where a member is necessary.</li>
	<li>If you try to call/use a delegate's private member, it will probably appear as a syntax error about not being able to find it in the struct rather than telling you that it is a private member of the delegate.</li>
</ul>

<h3 style="color: black"><a name="thistype"></a>thistype</h3>

<p>The thistype keyword behaves exactly as the struct's name in code that is inside a struct.</p>
<font face="monospace"> <font color="#008800">//The next code,</font><br>
<font color="#000000"><b>struct</b></font>&nbsp;<span style="background-color: #ffffff"><font color="#000000">test</font></span>&nbsp;<br>
&nbsp;&nbsp;&nbsp;&nbsp;<font color="#7777cc"><b>thistype</b></font>&nbsp;<font color="#7777cc"><b>array</b></font>&nbsp;<span style="background-color: #ffffff"><font color="#000000">ts</font></span><br>
&nbsp;&nbsp;&nbsp;&nbsp;<font color="#000000"><b>method</b></font>&nbsp;<span style="background-color: #ffffff"><font color="#000000">tester</font></span>&nbsp;<font color="#000000"><b>takes</b></font>&nbsp;<font color="#7777cc"><b>nothing</b></font>&nbsp;<font color="#000000"><b>returns</b></font>&nbsp;<font color="#7777cc"><b>thistype</b></font><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#000000"><b>return</b></font>&nbsp;<font color="#7777cc"><b>thistype</b></font><font color="#000066">.</font><span style="background-color: #ffffff"><font color="#000000">allocate</font></span>()<br>
&nbsp;&nbsp;&nbsp;&nbsp;<font color="#000000"><b>endmethod</b></font><br>
<font color="#000000"><b>endstruct</b></font><br>
<br>
<font color="#008800">//Is equivalent to:</font><br>
<br>
<font color="#000000"><b>struct</b></font>&nbsp;<span style="background-color: #ffffff"><font color="#000000">test</font></span>&nbsp;<br>
&nbsp;&nbsp;&nbsp;&nbsp;<span style="background-color: #ffffff"><font color="#000000">test</font></span>&nbsp;<font color="#7777cc"><b>array</b></font>&nbsp;<span style="background-color: #ffffff"><font color="#000000">ts</font></span><br>
&nbsp;&nbsp;&nbsp;&nbsp;<font color="#000000"><b>method</b></font>&nbsp;<span style="background-color: #ffffff"><font color="#000000">tester</font></span>&nbsp;<font color="#000000"><b>takes</b></font>&nbsp;<font color="#7777cc"><b>nothing</b></font>&nbsp;<font color="#000000"><b>returns</b></font>&nbsp;<span style="background-color: #ffffff"><font color="#000000">test</font></span><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#000000"><b>return</b></font>&nbsp;<span style="background-color: #ffffff"><font color="#000000">test</font></span><font color="#000066">.</font><span style="background-color: #ffffff"><font color="#000000">allocate</font></span>()<br>
&nbsp;&nbsp;&nbsp;&nbsp;<font color="#000000"><b>endmethod</b></font><br>
<font color="#000000"><b>endstruct</b></font></font>

<p>The intended usage for thistype, is when it is actually necessary, e.g: textmacros, modules. I do not endorse the idea of people using this so they can rename the struct later, but I guess they are allowed to.</p>

<h3 style="color: black"><a name="module"></a>Module</h3>

<p>A module is like a code package you can place in a struct to gain extra methods or members, etc. module, ..., endmodule are used to declare a module and implement is used to <i>copy</i> the module's members to the struct. Consider this as a high level textmacro.</p>

<p>methods in modules can call/use methods/members that belong to the struct (which could be private), just notice that if the struct does not have such members, a syntax error would pop up as if you were pasting the module's code into the struct. A module's private members will not be visible to the calling struct and their names will not conflict with other members in the struct, there are some exceptions, however: create, and onDestroy which will be handled differently later. You cannot have private operators in modules (operators are often meant for public APIs so it does not make any sense to make them private anyway).</p>

<p>Since Jasshelper 0.9.Z.1, private onInit methods inside a module will be executed on init once per struct implementing it. Multiple onInit methods from multiple modules can coexist with the struct's onInit method as well.</p>
<br>
<font face="monospace"><font color="#008800">///</font><br>
<font color="#008800">// Declare the module, similar to a struct declaration</font><br>
<font color="#008800">//</font><br>
<font color="#000000"><b>module</b></font>&nbsp;<span style="background-color: #ffffff"><font color="#000000">MyRepeatModule</font></span><br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;<font color="#000000"><b>method</b></font>&nbsp;<span style="background-color: #ffffff"><font color="#000000">repeat1000</font></span>&nbsp;<font color="#000000"><b>takes</b></font>&nbsp;<font color="#7777cc"><b>nothing</b></font>&nbsp;<font color="#000000"><b>returns</b></font>&nbsp;<font color="#7777cc"><b>nothing</b></font><br>
&nbsp;&nbsp;&nbsp;&nbsp; <font color="#000000"><b>local</b></font>&nbsp;<font color="#7777cc"><b>integer</b></font>&nbsp;<span style="background-color: #ffffff"><font color="#000000">i</font></span>=<font color="#000066">0</font><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#000000"><b>loop</b></font><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#000000"><b>exitwhen</b></font>&nbsp;<span style="background-color: #ffffff"><font color="#000000">i</font></span>==<font color="#000066">1000</font><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#000000"><b>call</b></font>&nbsp;<font color="#000066">this</font><font color="#000066">.</font><span style="background-color: #ffffff"><font color="#000000">sub</font></span>() <font color="#008800">//a method that is expected</font><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#008800">//to exist in the struct</font><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#000000"><b>set</b></font>&nbsp;<span style="background-color: #ffffff"><font color="#000000">i</font></span>=<span style="background-color: #ffffff"><font color="#000000">i</font></span>+<font color="#000066">1</font><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#000000"><b>endloop</b></font><br>
&nbsp;&nbsp;&nbsp;&nbsp;<font color="#000000"><b>endmethod</b></font><br>
<br>
<font color="#000000"><b>endmodule</b></font><br>
<br>
<font color="#008800">// the struct :</font><br>
<font color="#000000"><b>struct</b></font>&nbsp;<span style="background-color: #ffffff"><font color="#000000">MyStruct</font></span><br>
&nbsp;&nbsp;&nbsp;&nbsp;<font color="#000000"><b>method</b></font>&nbsp;<span style="background-color: #ffffff"><font color="#000000">sub</font></span>&nbsp;<font color="#000000"><b>takes</b></font>&nbsp;<font color="#7777cc"><b>nothing</b></font>&nbsp;<font color="#000000"><b>returns</b></font>&nbsp;<font color="#7777cc"><b>nothing</b></font><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#000000"><b>call</b></font>&nbsp;<span style="background-color: #ffffff"><font color="#000000">BJDebugMsg</font></span>(<font color="#0000cc"><i>"Hello world"</i></font>)<br>
&nbsp;&nbsp;&nbsp;&nbsp;<font color="#000000"><b>endmethod</b></font><br>
&nbsp;&nbsp;&nbsp;&nbsp;<font color="#000000"><b>implement</b></font>&nbsp;<span style="background-color: #ffffff"><font color="#000000">MyRepeatModule</font></span> <font color="#008800">//adds the module.</font><br>
<br>
<font color="#000000"><b>endstruct</b></font><br>
<br>
<font color="#000000"><b>function</b></font>&nbsp;<span style="background-color: #ffffff"><font color="#000000">MyTest</font></span>&nbsp;<font color="#000000"><b>takes</b></font>&nbsp;<span style="background-color: #ffffff"><font color="#000000">MyStruct</font></span>&nbsp;<span style="background-color: #ffffff"><font color="#000000">ms</font></span>&nbsp;<font color="#000000"><b>returns</b></font>&nbsp;<font color="#7777cc"><b>nothing</b></font><br>
&nbsp;&nbsp;&nbsp;&nbsp;<font color="#000000"><b>call</b></font>&nbsp;<span style="background-color: #ffffff"><font color="#000000">ms</font></span><font color="#000066">.</font><span style="background-color: #ffffff"><font color="#000000">repeat1000</font></span>() <font color="#008800">//will call ms.sub 1000 times.</font><br>
<font color="#000000"><b>endfunction</b></font></font>

<p>You can call other modules from inside a module using implement, adding the keyword optional after implement will make them module implementation optional, that is if the module cannot be found, no error will show up, vJass will just ignore the implement call. Another useful idea is to use thistype when necessary. If implement attempts to implement a module that has already been implemented in a struct, the call is ignored as well.</p>

<p>A module's contents obey the scope rules from the scope/library in which it is declared (if any).</p>
<br>
<font face="monospace"><font color="#000000"><b>module</b></font>&nbsp;<span style="background-color: #ffffff"><font color="#000000">MyOtherModule</font></span><br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;<font color="#000000"><b>method</b></font>&nbsp;<span style="background-color: #ffffff"><font color="#000000">uhOh</font></span>&nbsp;<font color="#000000"><b>takes</b></font>&nbsp;<font color="#7777cc"><b>nothing</b></font>&nbsp;<font color="#000000"><b>returns</b></font>&nbsp;<font color="#7777cc"><b>nothing</b></font><br>
&nbsp;&nbsp;&nbsp;&nbsp;<font color="#000000"><b>endmethod</b></font><br>
<font color="#000000"><b>endmodule</b></font><br>
<br>
<font color="#008800">///</font><br>
<font color="#008800">// Declare the module, similar to a struct declaration</font><br>
<font color="#008800">//</font><br>
<font color="#000000"><b>module</b></font>&nbsp;<span style="background-color: #ffffff"><font color="#000000">MyModule</font></span><br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;<font color="#008800">//next line adds a member uhOh that does nothing</font><br>
&nbsp;&nbsp;&nbsp;&nbsp;<font color="#000000"><b>implement</b></font>&nbsp;<font color="#000000"><b>optional</b></font>&nbsp;<span style="background-color: #ffffff"><font color="#000000">MyOtherModule</font></span><br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;<font color="#008800">//since OptionalModule is not declared, next line is ignored</font><br>
&nbsp;&nbsp;&nbsp;&nbsp;<font color="#000000"><b>implement</b></font>&nbsp;<font color="#000000"><b>optional</b></font>&nbsp;<span style="background-color: #ffffff"><font color="#000000">OptionalModule</font></span><br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;<font color="#008800">// This method call requires that the struct had</font><br>
&nbsp;&nbsp;&nbsp;&nbsp;<font color="#008800">//&nbsp;&nbsp;a copy() method</font><br>
&nbsp;&nbsp;&nbsp;&nbsp;<font color="#000000"><b>static</b></font>&nbsp;<font color="#000000"><b>method</b></font>&nbsp;<span style="background-color: #ffffff"><font color="#000000">swap</font></span>&nbsp;<font color="#000000"><b>takes</b></font>&nbsp;<font color="#7777cc"><b>thistype</b></font>&nbsp;<span style="background-color: #ffffff"><font color="#000000">A</font></span>&nbsp;, <font color="#7777cc"><b>thistype</b></font>&nbsp;<span style="background-color: #ffffff"><font color="#000000">B</font></span>&nbsp;<font color="#000000"><b>returns</b></font>&nbsp;<font color="#7777cc"><b>nothing</b></font><br>
&nbsp;&nbsp;&nbsp;&nbsp; <font color="#000000"><b>local</b></font>&nbsp;<font color="#7777cc"><b>thistype</b></font>&nbsp;<span style="background-color: #ffffff"><font color="#000000">C</font></span>&nbsp;= <font color="#7777cc"><b>thistype</b></font><font color="#000066">.</font><span style="background-color: #ffffff"><font color="#000000">allocate</font></span>()<br>
&nbsp;&nbsp;&nbsp;&nbsp; <font color="#008800">//we are from the inside, so can use allocate, even though it is private</font><br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#000000"><b>call</b></font>&nbsp;<span style="background-color: #ffffff"><font color="#000000">C</font></span><font color="#000066">.</font><span style="background-color: #ffffff"><font color="#000000">copy</font></span>(<span style="background-color: #ffffff"><font color="#000000">A</font></span>)<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#000000"><b>call</b></font>&nbsp;<span style="background-color: #ffffff"><font color="#000000">A</font></span><font color="#000066">.</font><span style="background-color: #ffffff"><font color="#000000">copy</font></span>(<span style="background-color: #ffffff"><font color="#000000">B</font></span>)<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#000000"><b>call</b></font>&nbsp;<span style="background-color: #ffffff"><font color="#000000">B</font></span><font color="#000066">.</font><span style="background-color: #ffffff"><font color="#000000">copy</font></span>(<span style="background-color: #ffffff"><font color="#000000">C</font></span>)<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#000000"><b>call</b></font>&nbsp;<span style="background-color: #ffffff"><font color="#000000">C</font></span><font color="#000066">.</font><span style="background-color: #ffffff"><font color="#000000">destroy</font></span>()<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br>
&nbsp;&nbsp;&nbsp;&nbsp;<font color="#000000"><b>endmethod</b></font><br>
<br>
<font color="#000000"><b>endmodule</b></font><br>
<br>
<font color="#008800">// the struct :</font><br>
<font color="#000000"><b>struct</b></font>&nbsp;<span style="background-color: #ffffff"><font color="#000000">MyStruct</font></span><br>
&nbsp;&nbsp;&nbsp;&nbsp;<font color="#7777cc"><b>integer</b></font>&nbsp;<span style="background-color: #ffffff"><font color="#000000">a</font></span><br>
&nbsp;&nbsp;&nbsp;&nbsp;<font color="#7777cc"><b>integer</b></font>&nbsp;<span style="background-color: #ffffff"><font color="#000000">b</font></span><br>
&nbsp;&nbsp;&nbsp;&nbsp;<font color="#7777cc"><b>integer</b></font>&nbsp;<span style="background-color: #ffffff"><font color="#000000">c</font></span><br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;<font color="#008800">//code a copy method</font><br>
&nbsp;&nbsp;&nbsp;&nbsp;<font color="#000000"><b>method</b></font>&nbsp;<span style="background-color: #ffffff"><font color="#000000">copy</font></span>&nbsp;<font color="#000000"><b>takes</b></font>&nbsp;<span style="background-color: #ffffff"><font color="#000000">MyStruct</font></span>&nbsp;<span style="background-color: #ffffff"><font color="#000000">x</font></span>&nbsp;<font color="#000000"><b>returns</b></font>&nbsp;<font color="#7777cc"><b>nothing</b></font><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#000000"><b>set</b></font>&nbsp;<font color="#000066">this</font><font color="#000066">.</font><span style="background-color: #ffffff"><font color="#000000">a</font></span>&nbsp;= <span style="background-color: #ffffff"><font color="#000000">x</font></span><font color="#000066">.</font><span style="background-color: #ffffff"><font color="#000000">a</font></span><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#000000"><b>set</b></font>&nbsp;<font color="#000066">this</font><font color="#000066">.</font><span style="background-color: #ffffff"><font color="#000000">b</font></span>&nbsp;= <span style="background-color: #ffffff"><font color="#000000">x</font></span><font color="#000066">.</font><span style="background-color: #ffffff"><font color="#000000">b</font></span><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#000000"><b>set</b></font>&nbsp;<font color="#000066">this</font><font color="#000066">.</font><span style="background-color: #ffffff"><font color="#000000">c</font></span>&nbsp;= <span style="background-color: #ffffff"><font color="#000000">x</font></span><font color="#000066">.</font><span style="background-color: #ffffff"><font color="#000000">c</font></span><br>
&nbsp;&nbsp;&nbsp;&nbsp;<font color="#000000"><b>endmethod</b></font><br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;<font color="#008800">//get the swap method "for free"</font><br>
&nbsp;&nbsp;&nbsp;&nbsp;<font color="#000000"><b>implement</b></font>&nbsp;<span style="background-color: #ffffff"><font color="#000000">MyModule</font></span><br>
&nbsp;&nbsp;&nbsp;&nbsp;<font color="#000000"><b>implement</b></font>&nbsp;<span style="background-color: #ffffff"><font color="#000000">MyOtherModule</font></span>&nbsp;<font color="#008800">//this module was already include by MyModule, so this line is ignored</font><br>
<br>
<font color="#000000"><b>endstruct</b></font><br>
<br>
<font color="#000000"><b>function</b></font>&nbsp;<span style="background-color: #ffffff"><font color="#000000">MyTest</font></span>&nbsp;<font color="#000000"><b>takes</b></font>&nbsp;<span style="background-color: #ffffff"><font color="#000000">MyStruct</font></span>&nbsp;<span style="background-color: #ffffff"><font color="#000000">A</font></span>, <span style="background-color: #ffffff"><font color="#000000">MyStruct</font></span>&nbsp;<span style="background-color: #ffffff"><font color="#000000">B</font></span>&nbsp;<font color="#000000"><b>returns</b></font>&nbsp;<font color="#7777cc"><b>nothing</b></font><br>
&nbsp;&nbsp;&nbsp;&nbsp;<font color="#000000"><b>call</b></font>&nbsp;<span style="background-color: #ffffff"><font color="#000000">MyStruct</font></span><font color="#000066">.</font><span style="background-color: #ffffff"><font color="#000000">swap</font></span>(<span style="background-color: #ffffff"><font color="#000000">A</font></span>,<span style="background-color: #ffffff"><font color="#000000">B</font></span>) <font color="#008800">//it now got that method afterall</font><br>
<font color="#000000"><b>endfunction</b></font></font>

<h3 style="color: black"><a name="funcobj"></a>Functions as objects</h3>

<p>For vJass functions may behave as objects with 2 methods: evaluate and execute, both methods got the same arguments list as the function, and evaluate got its return value as well.</p>

<p>Using functions as objects has a couple of advantages, evaluate() allows you to call the function even from code that is above its function declaration, execute allows the same but it is also able to run the function in another thread.</p>

<p>The disadvantages are: Functions that are used with evaluate(), should not use GetTriggeringTrigger() (but you may use any other event response) or any sync native, evaluate() does not support waits, and evaluate() is slower than a normal function call.</p>

<p>.execute() is actually faster than good old ExecuteFunc, and in later versions it might actually get even faster. evaluate halves the duration of ExecuteFunc and it may get much better later.</p>

<p>For functions that have function arguments you would have to use global variables to pass arguments when using ExecuteFunc, .execute and .evaluate will pass the arguments directly.</p>

<pre><font color="#000000"><b>function</b></font> <span style="background-color: #ffffff"><font color="#000000">A</font></span> <font color="#000000"><b>takes</b></font> <font color="#7777cc"><b>real</b></font> <span style="background-color: #ffffff"><font color="#000000">x</font></span> <font color="#000000"><b>returns</b></font> <font color="#7777cc"><b>real</b></font>
 <font color="#000000"><b>if</b></font>(<span style="background-color: #ffffff"><font color="#000000">GetRandomInt</font></span>(<font color="#000066">0</font>,<font color="#000066">1</font>)==<font color="#000066">0</font>) <font color="#000000"><b>then</b></font>
    <font color="#000000"><b>return</b></font> <span style="background-color: #ffffff"><font color="#000000">B</font></span>(<span style="background-color: #ffffff"><font color="#000000">x</font></span>*<font color="#000066">0.02</font>)
 <font color="#000000"><b>endif</b></font>
 <font color="#000000"><b>return</b></font> <span style="background-color: #ffffff"><font color="#000000">x</font></span>
<font color="#000000"><b>endfunction</b></font>

<font color="#000000"><b>function</b></font> <span style="background-color: #ffffff"><font color="#000000">B</font></span> <font color="#000000"><b>takes</b></font> <font color="#7777cc"><b>real</b></font> <span style="background-color: #ffffff"><font color="#000000">x</font></span> <font color="#000000"><b>returns</b></font> <font color="#7777cc"><b>real</b></font>
 <font color="#000000"><b>if</b></font>(<span style="background-color: #ffffff"><font color="#000000">GetRandomInt</font></span>(<font color="#000066">0</font>,<font color="#000066">1</font>)==<font color="#000066">1</font>) <font color="#000000"><b>then</b></font>
    <font color="#000000"><b>return</b></font> <span style="background-color: #ffffff"><font color="#000000">A</font></span>(<span style="background-color: #ffffff"><font color="#000000">x</font></span>*<font color="#000066">1000.</font>)
 <font color="#000000"><b>endif</b></font>
 <font color="#000000"><b>return</b></font> <span style="background-color: #ffffff"><font color="#000000">x</font></span>
<font color="#000000"><b>endfunction</b></font>
</pre>

<p>These are mutually recursive functions, and with normal Jass this would give a syntax error, in order to prevent this issue you may use evaluate:</p>

<pre><font color="#000000"><b>function</b></font> <span style="background-color: #ffffff"><font color="#000000">A</font></span> <font color="#000000"><b>takes</b></font> <font color="#7777cc"><b>real</b></font> <span style="background-color: #ffffff"><font color="#000000">x</font></span> <font color="#000000"><b>returns</b></font> <font color="#7777cc"><b>real</b></font>
 <font color="#000000"><b>if</b></font>(<span style="background-color: #ffffff"><font color="#000000">GetRandomInt</font></span>(<font color="#000066">0</font>,<font color="#000066">1</font>)==<font color="#000066">0</font>) <font color="#000000"><b>then</b></font>
    <font color="#000000"><b>return</b></font> <span style="background-color: #ffffff"><font color="#000000">B</font></span><font color="#000066">.</font><span style="background-color: #ffffff"><font color="#000000">evaluate</font></span>(<span style="background-color: #ffffff"><font color="#000000">x</font></span>*<font color="#000066">0.02</font>)
 <font color="#000000"><b>endif</b></font>
 <font color="#000000"><b>return</b></font> <span style="background-color: #ffffff"><font color="#000000">x</font></span>
<font color="#000000"><b>endfunction</b></font>

<font color="#000000"><b>function</b></font> <span style="background-color: #ffffff"><font color="#000000">B</font></span> <font color="#000000"><b>takes</b></font> <font color="#7777cc"><b>real</b></font> <span style="background-color: #ffffff"><font color="#000000">x</font></span> <font color="#000000"><b>returns</b></font> <font color="#7777cc"><b>real</b></font>
 <font color="#000000"><b>if</b></font>(<span style="background-color: #ffffff"><font color="#000000">GetRandomInt</font></span>(<font color="#000066">0</font>,<font color="#000066">1</font>)==<font color="#000066">1</font>) <font color="#000000"><b>then</b></font>
    <font color="#000000"><b>return</b></font> <span style="background-color: #ffffff"><font color="#000000">A</font></span>(<span style="background-color: #ffffff"><font color="#000000">x</font></span>*<font color="#000066">1000.</font>)
 <font color="#000000"><b>endif</b></font>
 <font color="#000000"><b>return</b></font> <span style="background-color: #ffffff"><font color="#000000">x</font></span>
<font color="#000000"><b>endfunction</b></font>
</pre>

<p>Let us say you need to destroy an special effect after waiting x seconds using a wait. You could use a timer but for example sake we are going to use a normal wait, we do not want to stop execution of the function calling this effect destroying function so we need a new thread:</p>

<pre><font color="#000000"><b>function</b></font> <span style="background-color: #ffffff"><font color="#000000">DestroyEffectAfter</font></span> <font color="#000000"><b>takes</b></font> <font color="#7777cc"><b>effect</b></font> <span style="background-color: #ffffff"><font color="#000000">fx</font></span>, <font color="#7777cc"><b>real</b></font> <span style="background-color: #ffffff"><font color="#000000">t</font></span> <font color="#000000"><b>returns</b></font> <font color="#7777cc"><b>nothing</b></font>
    <font color="#000000"><b>call</b></font> <span style="background-color: #ffffff"><font color="#000000">TriggerSleepAction</font></span>(<span style="background-color: #ffffff"><font color="#000000">t</font></span>)
    <font color="#000000"><b>call</b></font> <span style="background-color: #ffffff"><font color="#000000">DestroyEffect</font></span>(<span style="background-color: #ffffff"><font color="#000000">fx</font></span>)
<font color="#000000"><b>endfunction</b></font>

<font color="#000000"><b>function</b></font> <span style="background-color: #ffffff"><font color="#000000">test</font></span> <font color="#000000"><b>takes</b></font> <font color="#7777cc"><b>nothing</b></font> <font color="#000000"><b>returns</b></font> <font color="#7777cc"><b>nothing</b></font>
 <font color="#000000"><b>local</b></font> <font color="#7777cc"><b>unit</b></font> <span style="background-color: #ffffff"><font color="#000000">u</font></span>=<span style="background-color: #ffffff"><font color="#000000">GetTriggerUnit</font></span>()
 <font color="#000000"><b>local</b></font> <font color="#7777cc"><b>effect</b></font> <span style="background-color: #ffffff"><font color="#000000">f</font></span>=<span style="background-color: #ffffff"><font color="#000000">AddSpecialEffectTarget</font></span>(<font color="#0000cc"><i>"Abilities\\Spells\\Undead\\Cripple\\CrippleTarget.mdl"</i></font>,<span style="background-color: #ffffff"><font color="#000000">u</font></span>,<font color="#0000cc"><i>"chest"</i></font>)

  <font color="#000000"><b>call</b></font> <span style="background-color: #ffffff"><font color="#000000">DestroyEffectAfter</font></span><font color="#000066">.</font><span style="background-color: #ffffff"><font color="#000000">execute</font></span>(<span style="background-color: #ffffff"><font color="#000000">f</font></span>,<font color="#000066">3.0</font>)

  <font color="#000000"><b>set</b></font> <span style="background-color: #ffffff"><font color="#000000">u</font></span>=<span style="background-color: #ffffff"><font color="#000000">null</font></span>
  <font color="#000000"><b>set</b></font> <span style="background-color: #ffffff"><font color="#000000">f</font></span>=<span style="background-color: #ffffff"><font color="#000000">null</font></span>
<font color="#000000"><b>endfunction</b></font>
</pre>

<p><b>Note:</b> This feature is currently limited to functions declared in the map script, you cannot use it with common.j natives or blizzard.j functions yet.</p>

<p>The .name member in functions will return a string containing the function's compiled name, useful when you want to use a scope function in things like ExecuteFunc.</p>
<font face="monospace"> <font color="#000000"><b>scope</b></font>&nbsp;<span style="background-color: #ffffff"><font color="#000000">test</font></span><br>
&nbsp;&nbsp;&nbsp;&nbsp;<font color="#000000"><b>public</b></font>&nbsp;<font color="#000000"><b>function</b></font>&nbsp;<span style="background-color: #ffffff"><font color="#000000">xxx</font></span>&nbsp;<font color="#000000"><b>takes</b></font>&nbsp;<font color="#7777cc"><b>nothing</b></font>&nbsp;<font color="#000000"><b>returns</b></font>&nbsp;<font color="#7777cc"><b>nothing</b></font><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#000000"><b>call</b></font>&nbsp;<span style="background-color: #ffffff"><font color="#000000">BJDebugMsg</font></span>(<span style="background-color: #ffffff"><font color="#000000">xxx</font></span><font color="#000066">.</font><span style="background-color: #ffffff"><font color="#000000">name</font></span>) <font color="#008800">//will show "test_xxx"</font><br>
&nbsp;&nbsp;&nbsp;&nbsp;<font color="#000000"><b>endfunction</b></font><br>
<font color="#000000"><b>endscope</b></font></font>

<h3 style="color: black"><a name="funcinterf"></a>Function interfaces</h3>

<p>If functions are objects then we may as well have interfaces for them.</p>

<p>The syntax for function interfaces is: <b>function interface</b> name <b>takes</b> (arguments) <b>returns</b> (return value)</p>
It is actually similar to a function declaration.

<p>Variables/values of a function interface type may be called using execute() and evaluate() as defined above:</p>

<p>To assign to variables of a function interface type you first need to get a function's pointer. The syntax to get them is understandable if you assume that every declared function interface will get as static members the functions found in the map script that follow its argument/return value rules.</p>

<pre><font color="#000000"><b>function</b></font> <font color="#000000"><b>interface</b></font> <span style="background-color: #ffffff"><font color="#000000">Arealfunction</font></span> <font color="#000000"><b>takes</b></font> <font color="#7777cc"><b>real</b></font> <span style="background-color: #ffffff"><font color="#000000">x</font></span> <font color="#000000"><b>returns</b></font> <font color="#7777cc"><b>real</b></font>

<font color="#000000"><b>function</b></font> <span style="background-color: #ffffff"><font color="#000000">double</font></span> <font color="#000000"><b>takes</b></font> <font color="#7777cc"><b>real</b></font> <span style="background-color: #ffffff"><font color="#000000">x</font></span> <font color="#000000"><b>returns</b></font> <font color="#7777cc"><b>real</b></font>
    <font color="#000000"><b>return</b></font> <span style="background-color: #ffffff"><font color="#000000">x</font></span>*<font color="#000066">2.0</font>
<font color="#000000"><b>endfunction</b></font>

<font color="#000000"><b>function</b></font> <span style="background-color: #ffffff"><font color="#000000">triple</font></span> <font color="#000000"><b>takes</b></font> <font color="#7777cc"><b>real</b></font> <span style="background-color: #ffffff"><font color="#000000">x</font></span> <font color="#000000"><b>returns</b></font> <font color="#7777cc"><b>real</b></font>
    <font color="#000000"><b>return</b></font> <span style="background-color: #ffffff"><font color="#000000">x</font></span>*<font color="#000066">2.0</font>
<font color="#000000"><b>endfunction</b></font>

<font color="#000000"><b>function</b></font> <span style="background-color: #ffffff"><font color="#000000">Test1</font></span> <font color="#000000"><b>takes</b></font> <font color="#7777cc"><b>real</b></font> <span style="background-color: #ffffff"><font color="#000000">x</font></span>, <span style="background-color: #ffffff"><font color="#000000">Arealfunction</font></span> <span style="background-color: #ffffff"><font color="#000000">F</font></span> <font color="#000000"><b>returns</b></font> <font color="#7777cc"><b>real</b></font>
    <font color="#000000"><b>return</b></font> <span style="background-color: #ffffff"><font color="#000000">F</font></span><font color="#000066">.</font><span style="background-color: #ffffff"><font color="#000000">evaluate</font></span>(<span style="background-color: #ffffff"><font color="#000000">F</font></span><font color="#000066">.</font><span style="background-color: #ffffff"><font color="#000000">evaluate</font></span>(<span style="background-color: #ffffff"><font color="#000000">x</font></span>)*<span style="background-color: #ffffff"><font color="#000000">F</font></span><font color="#000066">.</font><span style="background-color: #ffffff"><font color="#000000">evaluate</font></span>(<span style="background-color: #ffffff"><font color="#000000">x</font></span>))
<font color="#000000"><b>endfunction</b></font>

<font color="#000000"><b>function</b></font> <span style="background-color: #ffffff"><font color="#000000">Test2</font></span> <font color="#000000"><b>takes</b></font> <font color="#7777cc"><b>nothing</b></font> <font color="#000000"><b>returns</b></font> <font color="#7777cc"><b>nothing</b></font>
 <font color="#000000"><b>local</b></font> <span style="background-color: #ffffff"><font color="#000000">Arealfunction</font></span> <span style="background-color: #ffffff"><font color="#000000">fun</font></span> = <span style="background-color: #ffffff"><font color="#000000">Arealfunction</font></span><font color="#000066">.</font><span style="background-color: #ffffff"><font color="#000000">double</font></span> <font color="#008800">//syntax to get pointer to function</font>

   <font color="#000000"><b>call</b></font> <span style="background-color: #ffffff"><font color="#000000">BJDebugMsg</font></span>( <span style="background-color: #ffffff"><font color="#000000">R2S</font></span>(  <span style="background-color: #ffffff"><font color="#000000">Test1</font></span>(<font color="#000066">1.2</font>, <span style="background-color: #ffffff"><font color="#000000">fun</font></span>) ))

   <font color="#000000"><b>call</b></font> <span style="background-color: #ffffff"><font color="#000000">BJDebugMsg</font></span>( <span style="background-color: #ffffff"><font color="#000000">R2S</font></span>(  <span style="background-color: #ffffff"><font color="#000000">Test1</font></span>(<font color="#000066">1.2</font>, <span style="background-color: #ffffff"><font color="#000000">Arealfunction</font></span><font color="#000066">.</font><span style="background-color: #ffffff"><font color="#000000">triple</font></span> ) )) <font color="#008800">//also possible...</font>
<font color="#000000"><b>endfunction</b></font>
</pre>

<p>In this example we are actually having functions as arguments and as a variable. You may also typecast(see bellow) a function pointer to integer and then back to the interface function it originated.</p>

<p>It is also possible to get a function pointer without typing the interface's name, notice that this will not allow you to validate the function as following the interface's declaration, but it is simpler nontheless.:/</p>

<p><font face="monospace"><font color="#008800">//repeat a call of the same function on a real variable thrice!</font><br>
<br>
<font color="#000000"><b>function</b></font>&nbsp;<span style="background-color: #ffffff"><font color="#000000">double</font></span>&nbsp;<font color="#000000"><b>takes</b></font>&nbsp;<font color="#7777cc"><b>real</b></font>&nbsp;<span style="background-color: #ffffff"><font color="#000000">x</font></span>&nbsp;<font color="#000000"><b>returns</b></font>&nbsp;<font color="#7777cc"><b>real</b></font><br>
&nbsp;&nbsp;&nbsp;&nbsp;<font color="#000000"><b>return</b></font>&nbsp;<font color="#000066">2</font>*<span style="background-color: #ffffff"><font color="#000000">x</font></span><br>
<font color="#000000"><b>endfunction</b></font><br>
<br>
<font color="#000000"><b>function</b></font>&nbsp;<span style="background-color: #ffffff"><font color="#000000">square</font></span>&nbsp;<font color="#000000"><b>takes</b></font>&nbsp;<font color="#7777cc"><b>real</b></font>&nbsp;<span style="background-color: #ffffff"><font color="#000000">x</font></span>&nbsp;<font color="#000000"><b>returns</b></font>&nbsp;<font color="#7777cc"><b>real</b></font><br>
&nbsp;&nbsp;&nbsp;&nbsp;<font color="#000000"><b>return</b></font>&nbsp;<span style="background-color: #ffffff"><font color="#000000">x</font></span>*<span style="background-color: #ffffff"><font color="#000000">x</font></span><br>
<font color="#000000"><b>endfunction</b></font><br>
<br>
&nbsp;&nbsp; <font color="#000000"><b>function</b></font>&nbsp;<font color="#000000"><b>interface</b></font>&nbsp;<span style="background-color: #ffffff"><font color="#000000">realfunc</font></span>&nbsp;<font color="#000000"><b>takes</b></font>&nbsp;<font color="#7777cc"><b>real</b></font>&nbsp;<span style="background-color: #ffffff"><font color="#000000">x</font></span>&nbsp;<font color="#000000"><b>returns</b></font>&nbsp;<font color="#7777cc"><b>real</b></font><br>
<br>
<font color="#000000"><b>function</b></font>&nbsp;<span style="background-color: #ffffff"><font color="#000000">repeater3</font></span>&nbsp;<font color="#000000"><b>takes</b></font>&nbsp;<font color="#7777cc"><b>real</b></font>&nbsp;<span style="background-color: #ffffff"><font color="#000000">x</font></span>, <span style="background-color: #ffffff"><font color="#000000">realfunc</font></span>&nbsp;<span style="background-color: #ffffff"><font color="#000000">F</font></span>&nbsp;<font color="#000000"><b>returns</b></font>&nbsp;<font color="#7777cc"><b>real</b></font><br>
&nbsp;&nbsp;&nbsp;&nbsp;<font color="#000000"><b>set</b></font>&nbsp;<span style="background-color: #ffffff"><font color="#000000">x</font></span>=<span style="background-color: #ffffff"><font color="#000000">F</font></span><font color="#000066">.</font><span style="background-color: #ffffff"><font color="#000000">evaluate</font></span>(<span style="background-color: #ffffff"><font color="#000000">x</font></span>)<br>
&nbsp;&nbsp;&nbsp;&nbsp;<font color="#000000"><b>set</b></font>&nbsp;<span style="background-color: #ffffff"><font color="#000000">x</font></span>=<span style="background-color: #ffffff"><font color="#000000">F</font></span><font color="#000066">.</font><span style="background-color: #ffffff"><font color="#000000">evaluate</font></span>(<span style="background-color: #ffffff"><font color="#000000">x</font></span>)<br>
&nbsp;&nbsp;&nbsp;&nbsp;<font color="#000000"><b>set</b></font>&nbsp;<span style="background-color: #ffffff"><font color="#000000">x</font></span>=<span style="background-color: #ffffff"><font color="#000000">F</font></span><font color="#000066">.</font><span style="background-color: #ffffff"><font color="#000000">evaluate</font></span>(<span style="background-color: #ffffff"><font color="#000000">x</font></span>)<br>
&nbsp;&nbsp;&nbsp;&nbsp;<font color="#000000"><b>return</b></font>&nbsp;<span style="background-color: #ffffff"><font color="#000000">x</font></span><br>
<font color="#000000"><b>endfunction</b></font><br>
<br>
<font color="#000000"><b>function</b></font>&nbsp;<span style="background-color: #ffffff"><font color="#000000">test</font></span>&nbsp;<font color="#000000"><b>takes</b></font>&nbsp;<font color="#7777cc"><b>nothing</b></font>&nbsp;<font color="#000000"><b>returns</b></font>&nbsp;<font color="#7777cc"><b>nothing</b></font><br>
&nbsp;<font color="#000000"><b>local</b></font>&nbsp;<font color="#7777cc"><b>real</b></font>&nbsp;<span style="background-color: #ffffff"><font color="#000000">x</font></span>&nbsp;= <span style="background-color: #ffffff"><font color="#000000">repeater3</font></span>( <font color="#000066">2.0</font>, <span style="background-color: #ffffff"><font color="#000000">double</font></span>) <font color="#008800">//notice we are just using the functions' names as if they were values.</font><br>
&nbsp;<font color="#000000"><b>local</b></font>&nbsp;<font color="#7777cc"><b>real</b></font>&nbsp;<span style="background-color: #ffffff"><font color="#000000">y</font></span>&nbsp;= <span style="background-color: #ffffff"><font color="#000000">repeater3</font></span>( <font color="#000066">2.0</font>, <span style="background-color: #ffffff"><font color="#000000">square</font></span>)<br>
<br>
&nbsp;&nbsp; <font color="#008800">//The results are x=16 and y=256.</font><br>
&nbsp;&nbsp; <font color="#008800">//explanation: the first is equivalent to:</font><br>
&nbsp;&nbsp; <font color="#008800">//&nbsp;&nbsp;&nbsp;&nbsp;set x=2</font><br>
&nbsp;&nbsp; <font color="#008800">//&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; set x=2*x</font><br>
&nbsp;&nbsp; <font color="#008800">//&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; set x=2*x</font><br>
&nbsp;&nbsp; <font color="#008800">//&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; set x=2*x</font><br>
&nbsp;&nbsp;<br>
&nbsp;&nbsp; <font color="#008800">// While the second is:</font><br>
&nbsp;&nbsp; <font color="#008800">//&nbsp;&nbsp;&nbsp;&nbsp;set y=2</font><br>
&nbsp;&nbsp; <font color="#008800">//&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; set y=y*y</font><br>
&nbsp;&nbsp; <font color="#008800">//&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; set y=y*y</font><br>
&nbsp;&nbsp; <font color="#008800">//&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; set y=y*y</font><br>
<br>
&nbsp;<font color="#008800">// yep, function interfaces allow you to use functions as if they were just another sort of variable.</font><br>
<font color="#000000"><b>endfunction</b></font></font></p>

<p>You may also use methods for function interfaces, the static method gets converted into a function pointer.</p>
<font face="monospace"> &nbsp;&nbsp;&nbsp;&nbsp;<font color="#000000"><b>function</b></font>&nbsp;<font color="#000000"><b>interface</b></font>&nbsp;<span style="background-color: #ffffff"><font color="#000000">myFunc</font></span>&nbsp;<font color="#000000"><b>takes</b></font>&nbsp;<font color="#7777cc"><b>integer</b></font>&nbsp;<span style="background-color: #ffffff"><font color="#000000">a</font></span>, <font color="#7777cc"><b>integer</b></font>&nbsp;<span style="background-color: #ffffff"><font color="#000000">b</font></span>&nbsp;<font color="#000000"><b>returns</b></font>&nbsp;<font color="#7777cc"><b>nothing</b></font><br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;<font color="#000000"><b>struct</b></font>&nbsp;<span style="background-color: #ffffff"><font color="#000000">try</font></span><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#000000"><b>static</b></font>&nbsp;<font color="#000000"><b>method</b></font>&nbsp;<span style="background-color: #ffffff"><font color="#000000">AAAA</font></span>&nbsp;<font color="#000000"><b>takes</b></font>&nbsp;<font color="#7777cc"><b>integer</b></font>&nbsp;<span style="background-color: #ffffff"><font color="#000000">a</font></span>, <font color="#7777cc"><b>integer</b></font>&nbsp;<span style="background-color: #ffffff"><font color="#000000">b</font></span>&nbsp;<font color="#000000"><b>returns</b></font>&nbsp;<font color="#7777cc"><b>nothing</b></font><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <font color="#000000"><b>call</b></font>&nbsp;<span style="background-color: #ffffff"><font color="#000000">BJDebugMsg</font></span>( <span style="background-color: #ffffff"><font color="#000000">I2S</font></span>(<span style="background-color: #ffffff"><font color="#000000">a</font></span>)+<font color="#0000cc"><i>", "</i></font>+<span style="background-color: #ffffff"><font color="#000000">I2S</font></span>(<span style="background-color: #ffffff"><font color="#000000">b</font></span>) )<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#000000"><b>endmethod</b></font><br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#000000"><b>method</b></font>&nbsp;<span style="background-color: #ffffff"><font color="#000000">ooz</font></span>&nbsp;<font color="#000000"><b>takes</b></font>&nbsp;<font color="#7777cc"><b>nothing</b></font>&nbsp;<font color="#000000"><b>returns</b></font>&nbsp;<font color="#7777cc"><b>nothing</b></font><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <font color="#000000"><b>local</b></font>&nbsp;<span style="background-color: #ffffff"><font color="#000000">myFunc</font></span>&nbsp;<span style="background-color: #ffffff"><font color="#000000">fun</font></span>&nbsp;= <span style="background-color: #ffffff"><font color="#000000">try</font></span><font color="#000066">.</font><span style="background-color: #ffffff"><font color="#000000">AAAA</font></span><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#000000"><b>call</b></font>&nbsp;<span style="background-color: #ffffff"><font color="#000000">fun</font></span><font color="#000066">.</font><span style="background-color: #ffffff"><font color="#000000">evaluate</font></span>(<font color="#000066">5</font>,<font color="#000066">6</font>)<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#000000"><b>call</b></font>&nbsp;<span style="background-color: #ffffff"><font color="#000000">fun</font></span><font color="#000066">.</font><span style="background-color: #ffffff"><font color="#000000">evaluate</font></span>(<font color="#000066">7</font>,<font color="#000066">8</font>)<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#000000"><b>endmethod</b></font><br>
&nbsp;&nbsp;&nbsp;&nbsp;<font color="#000000"><b>endstruct</b></font></font>

<p>Notice that non-static methods are usable as well for function interfaces. They behave as functions that take an integer in the first argument though.</p>

<p>When using non-static methods as function pointers, you are just converting them into functions that take an integer as first argument, the function pointer instance will require one of the struct's instances to get called.</p>
<font face="monospace"> <font color="#000000"><b>function</b></font>&nbsp;<font color="#000000"><b>interface</b></font>&nbsp;<span style="background-color: #ffffff"><font color="#000000">myFunc</font></span>&nbsp;<font color="#000000"><b>takes</b></font>&nbsp;<font color="#7777cc"><b>integer</b></font>&nbsp;<span style="background-color: #ffffff"><font color="#000000">x</font></span>&nbsp;<font color="#000000"><b>returns</b></font>&nbsp;<font color="#7777cc"><b>nothing</b></font><br>
<br>
<br>
<font color="#000000"><b>struct</b></font>&nbsp;<span style="background-color: #ffffff"><font color="#000000">TestStruct</font></span><br>
&nbsp;&nbsp;&nbsp;&nbsp;<font color="#7777cc"><b>string</b></font>&nbsp;<span style="background-color: #ffffff"><font color="#000000">msg</font></span><br>
&nbsp;&nbsp;&nbsp;&nbsp;<font color="#000000"><b>method</b></font>&nbsp;<span style="background-color: #ffffff"><font color="#000000">AAAA</font></span>&nbsp;<font color="#000000"><b>takes</b></font>&nbsp;<font color="#7777cc"><b>nothing</b></font>&nbsp;<font color="#000000"><b>returns</b></font>&nbsp;<font color="#7777cc"><b>nothing</b></font><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <font color="#000000"><b>call</b></font>&nbsp;<span style="background-color: #ffffff"><font color="#000000">BJDebugMsg</font></span>(<span style="background-color: #ffffff"><font color="#000000">msg</font></span>)<br>
&nbsp;&nbsp;&nbsp;&nbsp;<font color="#000000"><b>endmethod</b></font><br>
<font color="#000000"><b>endstruct</b></font><br>
<br>
<font color="#000000"><b>function</b></font>&nbsp;<span style="background-color: #ffffff"><font color="#000000">test</font></span>&nbsp;<font color="#000000"><b>takes</b></font>&nbsp;<font color="#7777cc"><b>nothing</b></font>&nbsp;<font color="#000000"><b>returns</b></font>&nbsp;<font color="#7777cc"><b>nothing</b></font><br>
&nbsp;<font color="#000000"><b>local</b></font>&nbsp;<span style="background-color: #ffffff"><font color="#000000">TestStruct</font></span>&nbsp;<span style="background-color: #ffffff"><font color="#000000">ts</font></span>&nbsp;= <span style="background-color: #ffffff"><font color="#000000">TestStruct</font></span><font color="#000066">.</font><span style="background-color: #ffffff"><font color="#000000">create</font></span>()<br>
&nbsp;<font color="#000000"><b>local</b></font>&nbsp;<span style="background-color: #ffffff"><font color="#000000">myFunc</font></span>&nbsp;<span style="background-color: #ffffff"><font color="#000000">mf</font></span><br>
&nbsp;&nbsp;&nbsp;&nbsp;<font color="#000000"><b>set</b></font>&nbsp;<span style="background-color: #ffffff"><font color="#000000">ts</font></span><font color="#000066">.</font><span style="background-color: #ffffff"><font color="#000000">msg</font></span>&nbsp;= <font color="#0000cc"><i>"!!! !!! !!! !!! "</i></font><br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;<font color="#000000"><b>set</b></font>&nbsp;<span style="background-color: #ffffff"><font color="#000000">mf</font></span>&nbsp;= <span style="background-color: #ffffff"><font color="#000000">TestStruct</font></span><font color="#000066">.</font><span style="background-color: #ffffff"><font color="#000000">AAAA</font></span><br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;<font color="#000000"><b>call</b></font>&nbsp;<span style="background-color: #ffffff"><font color="#000000">mf</font></span><font color="#000066">.</font><span style="background-color: #ffffff"><font color="#000000">evaluate</font></span>(<span style="background-color: #ffffff"><font color="#000000">ts</font></span>&nbsp;) <font color="#008800">//notice that we are explicitly feeding the function a instance</font><br>
<br>
<font color="#000000"><b>endfunction</b></font></font><br>
<br>
&nbsp;
<h3 style="color: black"><a name="typecast"></a>Typecast</h3>

<p>For the moment, assigning a value of an struct type to an integer variable / or variable of any other struct type will already change the type of that reference for the compiler</p>

<p>Notice that sometimes using a variable might get tedious or even create unneeded overhead, that is the reason the type cast operator was added.</p>

<p>Its syntax is mostly like a function but the name of the function is the name of a custom type. It will soon allow native types as well.</p>

<pre><font color="#000000"><b>interface</b></font>  <span style="background-color: #ffffff"><font color="#000000">wack</font></span>
    <font color="#008800">//... some declarations</font>
<font color="#000000"><b>endinterface</b></font>

<font color="#000000"><b>struct</b></font> <span style="background-color: #ffffff"><font color="#000000">wek</font></span> <font color="#000000"><b>extends</b></font> <span style="background-color: #ffffff"><font color="#000000">wack</font></span>
   <font color="#7777cc"><b>integer</b></font> <span style="background-color: #ffffff"><font color="#000000">x</font></span>
   <font color="#008800">// some more declarations</font>
<font color="#000000"><b>endstruct</b></font>

<font color="#000000"><b>function</b></font> <span style="background-color: #ffffff"><font color="#000000">test</font></span> <font color="#000000"><b>takes</b></font> <span style="background-color: #ffffff"><font color="#000000">wack</font></span> <span style="background-color: #ffffff"><font color="#000000">W</font></span> <font color="#000000"><b>returns</b></font> <font color="#7777cc"><b>nothing</b></font>
   <font color="#008800">//You are certain that W is of type wek, a way to cast the value is:</font>
 <font color="#000000"><b>local</b></font> <span style="background-color: #ffffff"><font color="#000000">wek</font></span> <span style="background-color: #ffffff"><font color="#000000">jo</font></span> = <span style="background-color: #ffffff"><font color="#000000">W</font></span>
   <font color="#000000"><b>set</b></font> <span style="background-color: #ffffff"><font color="#000000">jo</font></span><font color="#000066">.</font><span style="background-color: #ffffff"><font color="#000000">x</font></span>= <font color="#000066">5</font> <font color="#008800">//done</font>

   <font color="#008800">// but sometimes creating a variable is too much work for the virtual machine and you</font>
   <font color="#008800">// are only accessing it once </font>

   <font color="#000000"><b>set</b></font> <span style="background-color: #ffffff"><font color="#000000">wek</font></span>(<span style="background-color: #ffffff"><font color="#000000">W</font></span>)<font color="#000066">.</font><span style="background-color: #ffffff"><font color="#000000">x</font></span>=<font color="#000066">5</font> <font color="#008800">//also works.</font>
<font color="#000000"><b>endfunction</b></font>


<font color="#000000"><b>type</b></font> <span style="background-color: #ffffff"><font color="#000000">anarrayofdata</font></span> <font color="#000000"><b>extends</b></font> <font color="#7777cc"><b>integer</b></font> <font color="#7777cc"><b>array</b></font> [<font color="#000066">6</font>]

<font color="#000000"><b>function</b></font> <span style="background-color: #ffffff"><font color="#000000">getdata5</font></span> <font color="#000000"><b>takes</b></font> <font color="#7777cc"><b>unit</b></font> <span style="background-color: #ffffff"><font color="#000000">u</font></span> <font color="#000000"><b>returns</b></font> <font color="#7777cc"><b>integer</b></font>
    <font color="#008800">//a reference to an object of type anarrayofdata is saved as the unit's custom value</font>
    <font color="#000000"><b>return</b></font> <span style="background-color: #ffffff"><font color="#000000">anarrayofdata</font></span>(<span style="background-color: #ffffff"><font color="#000000">GetUnitUserData</font></span>(<span style="background-color: #ffffff"><font color="#000000">u</font></span>))[<font color="#000066">5</font>]
<font color="#000000"><b>endfunction</b></font>

<font color="#000000"><b>function</b></font> <span style="background-color: #ffffff"><font color="#000000">setdata5</font></span> <font color="#000000"><b>takes</b></font> <font color="#7777cc"><b>unit</b></font> <span style="background-color: #ffffff"><font color="#000000">u</font></span>, <span style="background-color: #ffffff"><font color="#000000">anarrayofdata</font></span> <span style="background-color: #ffffff"><font color="#000000">x</font></span> <font color="#000000"><b>returns</b></font> <font color="#7777cc"><b>nothing</b></font>
    <font color="#008800">// Here we are doing the opposite, notice that integer may be used as a type cast</font>
    <font color="#008800">// operator for struct and dynamic array types.</font>
    <font color="#000000"><b>call</b></font> <span style="background-color: #ffffff"><font color="#000000">SetUnitUserData</font></span>(<span style="background-color: #ffffff"><font color="#000000">u</font></span>,  <font color="#7777cc"><b>integer</b></font>(<span style="background-color: #ffffff"><font color="#000000">x</font></span>))
<font color="#000000"><b>endfunction</b></font>

</pre>

<h3 style="color: black"><a name="methodname"></a>Method function name</h3>

<p>Methods may work as objects to use the .execute()/.evaluate() feature, they may also work as objects to allow access to the name field. This .name field will return the function name given to a method after the compiling.</p>

<p>This is specially useful in case you want to use an struct's static method on an ExecuteFunc based system.</p>

<pre>

<font color="#000000"><b>struct</b></font> <span style="background-color: #ffffff"><font color="#000000">mystruct</font></span>
    <font color="#000000"><b>static</b></font> <font color="#000000"><b>method</b></font> <span style="background-color: #ffffff"><font color="#000000">mymethod</font></span> <font color="#000000"><b>takes</b></font> <font color="#0055aa"><b>nothing</b></font> <font color="#000000"><b>returns</b></font> <font color="#0055aa"><b>nothing</b></font>
        <font color="#000000"><b>call</b></font> <span style="background-color: #ffffff"><font color="#000000">BJDebugMsg</font></span>(<font color="#0000aa"><i>"this works"</i></font>)
    <font color="#000000"><b>endmethod</b></font>
<font color="#000000"><b>endstruct</b></font>

<font color="#000000"><b>function</b></font> <span style="background-color: #ffffff"><font color="#000000">myfunction</font></span> <font color="#000000"><b>takes</b></font> <font color="#0055aa"><b>nothing</b></font> <font color="#000000"><b>returns</b></font> <font color="#0055aa"><b>nothing</b></font>
    <font color="#000000"><b>call</b></font> <span style="background-color: #ffffff"><font color="#000000">ExecuteFunc</font></span>(<span style="background-color: #ffffff"><font color="#000000">mystruct</font></span><font color="#0000aa">.</font><span style="background-color: #ffffff"><font color="#000000">mymethod</font></span><font color="#0000aa">.</font><span style="background-color: #ffffff"><font color="#000000">name</font></span>) <font color="#008800">//ExecuteFunc compatibility</font>

    <font color="#000000"><b>call</b></font> <span style="background-color: #ffffff"><font color="#000000">OnAbilityCast</font></span>(<font color="#0000aa">'A000'</font>,<span style="background-color: #ffffff"><font color="#000000">mystruct</font></span><font color="#0000aa">.</font><span style="background-color: #ffffff"><font color="#000000">mymethod</font></span><font color="#0000aa">.</font><span style="background-color: #ffffff"><font color="#000000">name</font></span>)
    <font color="#008800">//for example, caster system's OnAbilityCast, requires a function name</font>
<font color="#000000"><b>endfunction</b></font>
</pre>

<h3 style="color: black"><a name="methodexists"></a>Method exists</h3>

<p>Another field used by methods is the exists field, it is a boolean field that returns true if the method has been declared or false otherwise. Most of the times it would be true, the only case whatsoever in which it could be false is if the struct is extending a interface that uses defaults for the method.</p>
<font face="monospace"> <font color="#000000"><b>interface</b></font>&nbsp;<span style="background-color: #ffffff"><font color="#000000">myInterface</font></span><br>
&nbsp;&nbsp;&nbsp;&nbsp;<font color="#000000"><b>method</b></font>&nbsp;<span style="background-color: #ffffff"><font color="#000000">myMethod1</font></span>&nbsp;<font color="#000000"><b>takes</b></font>&nbsp;<font color="#7777cc"><b>nothing</b></font>&nbsp;<font color="#000000"><b>returns</b></font>&nbsp;<font color="#7777cc"><b>nothing</b></font><br>
&nbsp;&nbsp;&nbsp;&nbsp;<font color="#000000"><b>method</b></font>&nbsp;<span style="background-color: #ffffff"><font color="#000000">myMethod2</font></span>&nbsp;<font color="#000000"><b>takes</b></font>&nbsp;<font color="#7777cc"><b>nothing</b></font>&nbsp;<font color="#000000"><b>returns</b></font>&nbsp;<font color="#7777cc"><b>nothing</b></font><br>
<font color="#000000"><b>endinterface</b></font><br>
<br>
<font color="#000000"><b>struct</b></font>&nbsp;<span style="background-color: #ffffff"><font color="#000000">myStruct</font></span><br>
&nbsp;&nbsp;&nbsp;&nbsp;<font color="#000000"><b>method</b></font>&nbsp;<span style="background-color: #ffffff"><font color="#000000">myMethod1</font></span>&nbsp;<font color="#000000"><b>takes</b></font>&nbsp;<font color="#7777cc"><b>nothing</b></font>&nbsp;<font color="#000000"><b>returns</b></font>&nbsp;<font color="#7777cc"><b>nothing</b></font><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#000000"><b>call</b></font>&nbsp;<span style="background-color: #ffffff"><font color="#000000">BJDebugMsg</font></span>(<font color="#0000cc"><i>"er"</i></font>)<br>
&nbsp;&nbsp;&nbsp;&nbsp;<font color="#000000"><b>endmethod</b></font><br>
<font color="#000000"><b>endstruct</b></font><br>
<br>
<font color="#000000"><b>function</b></font>&nbsp;<span style="background-color: #ffffff"><font color="#000000">test</font></span>&nbsp;<font color="#000000"><b>takes</b></font>&nbsp;<font color="#7777cc"><b>nothing</b></font>&nbsp;<font color="#000000"><b>returns</b></font>&nbsp;<font color="#7777cc"><b>nothing</b></font><br>
&nbsp;<font color="#000000"><b>local</b></font>&nbsp;<span style="background-color: #ffffff"><font color="#000000">myInterface</font></span>&nbsp;<span style="background-color: #ffffff"><font color="#000000">mi</font></span>&nbsp;= <span style="background-color: #ffffff"><font color="#000000">myStruct</font></span><font color="#000066">.</font><span style="background-color: #ffffff"><font color="#000000">create</font></span>()<br>
&nbsp;&nbsp;&nbsp;&nbsp;<font color="#008800">//outputs:</font><br>
&nbsp;&nbsp;&nbsp;&nbsp;<font color="#008800">// yes</font><br>
&nbsp;&nbsp;&nbsp;&nbsp;<font color="#008800">// no</font><br>
&nbsp;&nbsp;&nbsp;&nbsp;<font color="#000000"><b>if</b></font>( <span style="background-color: #ffffff"><font color="#000000">mi</font></span><font color="#000066">.</font><span style="background-color: #ffffff"><font color="#000000">myMethod1</font></span><font color="#000066">.</font><span style="background-color: #ffffff"><font color="#000000">exists</font></span>) <font color="#000000"><b>then</b></font><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#000000"><b>call</b></font>&nbsp;<span style="background-color: #ffffff"><font color="#000000">BJDebugMsg</font></span>(<font color="#0000cc"><i>"Yes"</i></font>)<br>
&nbsp;&nbsp;&nbsp;&nbsp;<font color="#000000"><b>else</b></font><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#000000"><b>call</b></font>&nbsp;<span style="background-color: #ffffff"><font color="#000000">BJDebugMsg</font></span>(<font color="#0000cc"><i>"No"</i></font>)<br>
&nbsp;&nbsp;&nbsp;&nbsp;<font color="#000000"><b>endif</b></font><br>
&nbsp;&nbsp;&nbsp;&nbsp;<font color="#000000"><b>if</b></font>( <span style="background-color: #ffffff"><font color="#000000">mi</font></span><font color="#000066">.</font><span style="background-color: #ffffff"><font color="#000000">myMethod2</font></span><font color="#000066">.</font><span style="background-color: #ffffff"><font color="#000000">exists</font></span>) <font color="#000000"><b>then</b></font><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#000000"><b>call</b></font>&nbsp;<span style="background-color: #ffffff"><font color="#000000">BJDebugMsg</font></span>(<font color="#0000cc"><i>"Yes"</i></font>)<br>
&nbsp;&nbsp;&nbsp;&nbsp;<font color="#000000"><b>else</b></font><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#000000"><b>call</b></font>&nbsp;<span style="background-color: #ffffff"><font color="#000000">BJDebugMsg</font></span>(<font color="#0000cc"><i>"No"</i></font>)<br>
&nbsp;&nbsp;&nbsp;&nbsp;<font color="#000000"><b>endif</b></font><br>
<br>
<font color="#000000"><b>endfunction</b></font> </font>

<h3 style="color: black"><a name="arrstruct"></a>Array structs</h3>

<p>Sometimes, you'd like to have a global array of a struct type, just to be able to have that field syntax we all like so much, it can be more complicated than it is supposed to, for example you have to manually initialize all the indexes to create the unique indexes, etc. Another issue is when you do not really want to use .allocate() and .destroy() you would like to have your own ways for allocation. Array structs are a small syntax enhancement that is equivalent to an array of a struct type, you would be able to use the members for each index and you will not have to worry about .create().</p>
<font face="monospace"> <font color="#008800">//Array structs are hard to explain, but should be simple to understand with an example</font><br>
<br>
<font color="#000000"><b>struct</b></font>&nbsp;<span style="background-color: #ffffff"><font color="#000000">playerdata</font></span>&nbsp;<font color="#000000"><b>extends</b></font>&nbsp;<font color="#7777cc"><b>array</b></font>&nbsp;<font color="#008800">//syntax to declare an array struct</font><br>
&nbsp;&nbsp;&nbsp;&nbsp;<font color="#7777cc"><b>integer</b></font>&nbsp;<span style="background-color: #ffffff"><font color="#000000">a</font></span><br>
&nbsp;&nbsp;&nbsp;&nbsp;<font color="#7777cc"><b>integer</b></font>&nbsp;<span style="background-color: #ffffff"><font color="#000000">b</font></span><br>
&nbsp;&nbsp;&nbsp;&nbsp;<font color="#7777cc"><b>integer</b></font>&nbsp;<span style="background-color: #ffffff"><font color="#000000">c</font></span><br>
<font color="#000000"><b>endstruct</b></font><br>
<br>
<font color="#000000"><b>function</b></font>&nbsp;<span style="background-color: #ffffff"><font color="#000000">init</font></span>&nbsp;<font color="#000000"><b>takes</b></font>&nbsp;<font color="#7777cc"><b>nothing</b></font>&nbsp;<font color="#000000"><b>returns</b></font>&nbsp;<font color="#7777cc"><b>nothing</b></font><br>
&nbsp;<font color="#000000"><b>local</b></font>&nbsp;<span style="background-color: #ffffff"><font color="#000000">playerdata</font></span>&nbsp;<span style="background-color: #ffffff"><font color="#000000">pd</font></span><br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;<font color="#000000"><b>set</b></font>&nbsp;<span style="background-color: #ffffff"><font color="#000000">playerdata</font></span><font color="#000066">[3].</font><span style="background-color: #ffffff"><font color="#000000">a</font></span>=<font color="#000066">12</font>&nbsp;&nbsp;<font color="#008800">//modifying player 3's fields.</font><br>
&nbsp;&nbsp;&nbsp;&nbsp;<font color="#000000"><b>set</b></font>&nbsp;<span style="background-color: #ffffff"><font color="#000000">playerdata</font></span><font color="#000066">[3].</font><span style="background-color: #ffffff"><font color="#000000">b</font></span>=<font color="#000066">34</font>&nbsp;&nbsp;<font color="#008800">//notice it behaves as a global array</font><br>
&nbsp;&nbsp;&nbsp;&nbsp;<font color="#000000"><b>set</b></font>&nbsp;<span style="background-color: #ffffff"><font color="#000000">playerdata</font></span><font color="#000066">[3].</font><span style="background-color: #ffffff"><font color="#000000">c</font></span>=<font color="#000066">500</font><br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;<font color="#000000"><b>set</b></font>&nbsp;<span style="background-color: #ffffff"><font color="#000000">pd</font></span>=<span style="background-color: #ffffff"><font color="#000000">playerdata</font></span>[<font color="#000066">4</font>]<br>
&nbsp;&nbsp;&nbsp;&nbsp;<font color="#000000"><b>set</b></font>&nbsp;<span style="background-color: #ffffff"><font color="#000000">pd</font></span><font color="#000066">.</font><span style="background-color: #ffffff"><font color="#000000">a</font></span>=<font color="#000066">17</font>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <font color="#008800">//modifying player 4's fields.</font><br>
&nbsp;&nbsp;&nbsp;&nbsp;<font color="#000000"><b>set</b></font>&nbsp;<span style="background-color: #ffffff"><font color="#000000">pd</font></span><font color="#000066">.</font><span style="background-color: #ffffff"><font color="#000000">b</font></span>=<font color="#000066">111</font>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#008800">//yep, this is also valid</font><br>
&nbsp;&nbsp;&nbsp;&nbsp;<font color="#000000"><b>set</b></font>&nbsp;<span style="background-color: #ffffff"><font color="#000000">pd</font></span><font color="#000066">.</font><span style="background-color: #ffffff"><font color="#000000">c</font></span>=<font color="#000066">501</font><br>
<font color="#000000"><b>endfunction</b></font><br>
<br>
<font color="#000000"><b>function</b></font>&nbsp;<span style="background-color: #ffffff"><font color="#000000">updatePlayerStuff</font></span>&nbsp;<font color="#000000"><b>takes</b></font>&nbsp;<font color="#7777cc"><b>player</b></font>&nbsp;<span style="background-color: #ffffff"><font color="#000000">p</font></span>&nbsp;<font color="#000000"><b>returns</b></font>&nbsp;<font color="#7777cc"><b>nothing</b></font><br>
&nbsp;<font color="#000000"><b>local</b></font>&nbsp;<font color="#7777cc"><b>integer</b></font>&nbsp;<span style="background-color: #ffffff"><font color="#000000">i</font></span>=<span style="background-color: #ffffff"><font color="#000000">GetPlayerId</font></span>(<span style="background-color: #ffffff"><font color="#000000">p</font></span>)<br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;<font color="#008800">//some random function.</font><br>
&nbsp;&nbsp;&nbsp;&nbsp;<font color="#000000"><b>set</b></font>&nbsp;<span style="background-color: #ffffff"><font color="#000000">playerdata</font></span>[<span style="background-color: #ffffff"><font color="#000000">i</font></span><font color="#000066">].</font><span style="background-color: #ffffff"><font color="#000000">a</font></span>=<span style="background-color: #ffffff"><font color="#000000">playerdata</font></span>[<span style="background-color: #ffffff"><font color="#000000">i</font></span><font color="#000066">].</font><span style="background-color: #ffffff"><font color="#000000">b</font></span><br>
<br>
<font color="#000000"><b>endfunction</b></font></font>

<p>Certain issues with array structs: You cannot declare default values (they would automatically be zero, null or false depending on the type of the member) , you cannot declare onDestroy (it would be pointless), you cannot use .allocate or .destroy, you cannot have array members. Notice that the problem with default values and array members are likely to be fixed in a next version.</p>

<p>Notice that you can use operator declarations to override the get [] operator, in this case, to be able to use ids you would be able to use the typecast operator, e.g. playerdata(4) to get the instances. If you did not understand this last paragraph, don't worry, you probably did not need to know this anyway.</p>

<h3 style="color: black"><a name="keykeykey"></a>Keys</h3>

<p>key is a special vJass type that is meant to generate unique integer constants you can use in various ways, it is mostly intended to be used for key generation for warcraft 3's hashtable handle type.</p>

<p>Whenever you use the key type to declare a variable, a unique integer number is assigned to it. You may add the constant keyword for extra readability if you want.</p>
<font face="monospace"> <font color="#000000"><b>scope</b></font>&nbsp;<span style="background-color: #ffffff"><font color="#000000">Tester</font></span>&nbsp;<font color="#000000"><b>initializer</b></font>&nbsp;<span style="background-color: #ffffff"><font color="#000000">test</font></span><br>
<br>
<font color="#000000"><b>globals</b></font><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <font color="#7777cc"><b>key</b></font>&nbsp;<span style="background-color: #ffffff"><font color="#000000">AAAA</font></span><br>
&nbsp;&nbsp;&nbsp;&nbsp;<font color="#000000"><b>private</b></font>&nbsp;&nbsp;<font color="#7777cc"><b>key</b></font>&nbsp;<span style="background-color: #ffffff"><font color="#000000">BBBB</font></span>&nbsp;<font color="#008800">// yes it is just another type, so you can have</font><br>
&nbsp;&nbsp;&nbsp;&nbsp;<font color="#000000"><b>public</b></font>&nbsp;&nbsp; <font color="#7777cc"><b>key</b></font>&nbsp;<span style="background-color: #ffffff"><font color="#000000">CCCC</font></span>&nbsp;<font color="#008800">// public or private ones...</font><br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;<font color="#000000"><b>constant</b></font>&nbsp;<font color="#7777cc"><b>key</b></font>&nbsp;<span style="background-color: #ffffff"><font color="#000000">DDDD</font></span>&nbsp;&nbsp;<font color="#008800">//correctly describe it as a constant (not necessary)</font><br>
<font color="#000000"><b>endglobals</b></font><br>
<br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;<font color="#000000"><b>private</b></font>&nbsp;<font color="#000000"><b>function</b></font>&nbsp;<span style="background-color: #ffffff"><font color="#000000">test</font></span>&nbsp;<font color="#000000"><b>takes</b></font>&nbsp;<font color="#7777cc"><b>nothing</b></font>&nbsp;<font color="#000000"><b>returns</b></font>&nbsp;<font color="#7777cc"><b>nothing</b></font><br>
&nbsp;&nbsp;&nbsp;&nbsp; <font color="#000000"><b>local</b></font>&nbsp;<font color="#7777cc"><b>hashtable</b></font>&nbsp;<span style="background-color: #ffffff"><font color="#000000">ht</font></span>&nbsp;= <span style="background-color: #ffffff"><font color="#000000">InitHashtable</font></span>()<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#000000"><b>call</b></font>&nbsp;<span style="background-color: #ffffff"><font color="#000000">SaveInteger</font></span>(<span style="background-color: #ffffff"><font color="#000000">ht</font></span>, <span style="background-color: #ffffff"><font color="#000000">AAAA</font></span>, <span style="background-color: #ffffff"><font color="#000000">BBBB</font></span>, <font color="#000066">5</font>)<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#000000"><b>call</b></font>&nbsp;<span style="background-color: #ffffff"><font color="#000000">SaveInteger</font></span>(<span style="background-color: #ffffff"><font color="#000000">ht</font></span>, <span style="background-color: #ffffff"><font color="#000000">AAAA</font></span>, <span style="background-color: #ffffff"><font color="#000000">CCCC</font></span>, <font color="#000066">7</font>)<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#000000"><b>call</b></font>&nbsp;<span style="background-color: #ffffff"><font color="#000000">SaveReal</font></span>(<span style="background-color: #ffffff"><font color="#000000">ht</font></span>, <span style="background-color: #ffffff"><font color="#000000">AAAA</font></span>, <span style="background-color: #ffffff"><font color="#000000">DDDD</font></span>, <span style="background-color: #ffffff"><font color="#000000">LoadInteger</font></span>(<span style="background-color: #ffffff"><font color="#000000">ht</font></span>,<span style="background-color: #ffffff"><font color="#000000">AAAA</font></span>, <span style="background-color: #ffffff"><font color="#000000">BBBB</font></span>) * <font color="#000066">0.05</font>&nbsp;)<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#000000"><b>call</b></font>&nbsp;<span style="background-color: #ffffff"><font color="#000000">BJDebugMsg</font></span>( <span style="background-color: #ffffff"><font color="#000000">R2S</font></span>( <span style="background-color: #ffffff"><font color="#000000">LoadReal</font></span>(<span style="background-color: #ffffff"><font color="#000000">ht</font></span>,<span style="background-color: #ffffff"><font color="#000000">AAAA</font></span>,<span style="background-color: #ffffff"><font color="#000000">DDDD</font></span>) ) )<br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#000000"><b>call</b></font>&nbsp;<span style="background-color: #ffffff"><font color="#000000">BJDebugMsg</font></span>( <span style="background-color: #ffffff"><font color="#000000">I2S</font></span>(<span style="background-color: #ffffff"><font color="#000000">BBBB</font></span>) ) <font color="#008800">// will show two numbers, and</font><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#000000"><b>call</b></font>&nbsp;<span style="background-color: #ffffff"><font color="#000000">BJDebugMsg</font></span>( <span style="background-color: #ffffff"><font color="#000000">I2S</font></span>(<span style="background-color: #ffffff"><font color="#000000">CCCC</font></span>) ) <font color="#008800">// the numbers will be different...</font><br>
&nbsp;&nbsp;&nbsp;&nbsp;<font color="#000000"><b>endfunction</b></font><br>
<br>
<font color="#000000"><b>endscope</b></font></font>

<h2 style="color: black">Storage enhancers</h2>

<h3 style="color: black"><a name="storintro"></a>Introduction</h3>

<p>There is an internal limit in Jass regarding array sizes, jasshelper is widely affected by it since it directly affects struct instance limits, for example. There is a way to virtually increase the limit by combining together a number of Jass arrays and translate indexes of the bigger array into indexes of the smaller arrays.</p>

<p>By using storage enhancer syntax you can make Jasshelper do this trick. But there is a catch, by increasing the limit of available indexes you make sacrifices of many kinds:</p>

<ul>
	<li>Operations that would usually just need an array lookup would require a function call instead, function calls are very slow in Jass in comparison to array lookups.</li>
	<li>The function requires to do some extra operations itself, currently the number of operations these functions take depends on (index_limit / 8191), soon a jasshelper improvement might allowe them to do log_2(index_limit/8191), notice that for smaller index limits this improvement is not important.</li>
	<li>The script size can increase significantly if you use very big index limits, on a lot of objects, for example if your struct got 20 fields and you use an index limit of 60000, the compiled script will require 40 new functions each with a little more than 16 lines.</li>
</ul>

<p>Some Jass applications will require more space which means you would have to use enhancers regardless of the limitations, in case you do not really need more space, using these enhancers is discouraged because of the cons described above, if you are making a flexible system that might or might not require these enhancements you can make the enhancer usage optional, because space syntax allows you to use constant variables in its declaration you can make the user able to determine it, if you use size enhancer syntax to specify a size not bigger than 8191 (or 8190 in the case of structs, since you also need the 0 instance) nothing will happen and the penalties described above will not apply.</p>

<p>An internal jasshelper limit forbids a declaration that would require the script to use more than 8 arrays for the same big array, leading to an index space limit of around 408000, if you need more space, request so but include a good description of the (rather crazy) thing you are doing that requires so much space, I am interested in learning about it...</p>

<h3 style="color: black"><a name="storarray"></a>Sized arrays</h3>

<p>Global arrays might sometimes require more index space, jasshelper introduces syntax for sized arrays, it serves two purposes: It will allow you to request more space, and it also allows you to place a .size field on global arrays.</p>

<pre><font color="#000000"><b>globals</b></font>
    <font color="#7777cc"><b>integer</b></font> <font color="#7777cc"><b>array</b></font> <span style="background-color: #ffffff"><font color="#000000">myArray</font></span> [<font color="#000066">500</font>]
<font color="#000000"><b>endglobals</b></font>

<font color="#000000"><b>function</b></font> <span style="background-color: #ffffff"><font color="#000000">test</font></span> <font color="#000000"><b>takes</b></font> <font color="#7777cc"><b>nothing</b></font> <font color="#000000"><b>returns</b></font> <font color="#7777cc"><b>nothing</b></font>
 <font color="#000000"><b>local</b></font> <font color="#7777cc"><b>integer</b></font> <span style="background-color: #ffffff"><font color="#000000">i</font></span>=<font color="#000066">0</font>

    <font color="#000000"><b>call</b></font> <span style="background-color: #ffffff"><font color="#000000">BJDebugMsg</font></span>(<span style="background-color: #ffffff"><font color="#000000">I2S</font></span>(<span style="background-color: #ffffff"><font color="#000000">myArray</font></span><font color="#000066">.</font><span style="background-color: #ffffff"><font color="#000000">size</font></span>)) <font color="#008800">//prints 500</font>

    <font color="#000000"><b>loop</b></font>
        <font color="#000000"><b>exitwhen</b></font> <span style="background-color: #ffffff"><font color="#000000">i</font></span>&gt;=<span style="background-color: #ffffff"><font color="#000000">myArray</font></span><font color="#000066">.</font><span style="background-color: #ffffff"><font color="#000000">size</font></span>
        <font color="#000000"><b>set</b></font> <span style="background-color: #ffffff"><font color="#000000">myArray</font></span>[<span style="background-color: #ffffff"><font color="#000000">i</font></span>]=<span style="background-color: #ffffff"><font color="#000000">i</font></span>
        <font color="#000000"><b>set</b></font> <span style="background-color: #ffffff"><font color="#000000">i</font></span>=<span style="background-color: #ffffff"><font color="#000000">i</font></span>+<font color="#000066">1</font>
    <font color="#000000"><b>endloop</b></font>
<font color="#000000"><b>endfunction</b></font>
</pre>

<p>Of course, you can bypass the 8191 array size limit:</p>

<pre>
<font color="#000000"><b>globals</b></font>
    <font color="#7777cc"><b>integer</b></font> <font color="#7777cc"><b>array</b></font> <span style="background-color: #ffffff"><font color="#000000">myArray</font></span> [<font color="#000066">9000</font>]
<font color="#000000"><b>endglobals</b></font>
</pre>

<p>You can use a constant as well:</p>

<pre><font color="#000000"><b>globals</b></font>
    <font color="#000000"><b>constant</b></font> <font color="#7777cc"><b>integer</b></font> <span style="background-color: #ffffff"><font color="#000000">Q</font></span>= <font color="#000066">60000</font>
    <font color="#7777cc"><b>integer</b></font> <font color="#7777cc"><b>array</b></font> <span style="background-color: #ffffff"><font color="#000000">myArray</font></span> [<span style="background-color: #ffffff"><font color="#000000">Q</font></span>]
<font color="#000000"><b>endglobals</b></font>
</pre>

<p>You can use this on struct static member arrays. (static integer A[10000])</p>

<h3 style="color: black"><a name="twodarray"></a>2D arrays</h3>

<p>A quick improvement from sized arrays, is the ability to have two-dimensional arrays, n-dimensional arrays are not implemented, if you really need it very hard, contact me.</p>

<p>Two dimensional arrays in vJass, since vJass is implemented on top of Jass, are just normal arrays in disguise, using a multiplication trick to convert 2-dimension indexes into a one-dimension one. The way to declare one of these arrays is: <b>&lt;type&gt; array</b> name[<b>width</b>][<b>height</b>], notice the real size of the array is width*height, this size suffers the same limitations as normal array's size, it cannot go above approximately 40800, and if this size is bigger than 8191, you will be using slower function calls instead of array lookups and multiple arrays in the final script, etc.</p>

<p>The field size would return this total size we are talking about, the fields height and width return the ones we used to declare the array. As with sized arrays, you can use constants for the width and size.</p>
<br>
<font face="monospace">&nbsp;&nbsp; <font color="#000000"><b>globals</b></font><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <font color="#7777cc"><b>integer</b></font>&nbsp;<font color="#7777cc"><b>array</b></font>&nbsp;<span style="background-color: #ffffff"><font color="#000000">mat1</font></span>&nbsp;[<font color="#000066">10</font>][<font color="#000066">20</font>]<br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <font color="#000000"><b>constant</b></font>&nbsp;<font color="#7777cc"><b>integer</b></font>&nbsp;<span style="background-color: #ffffff"><font color="#000000">W</font></span>=<font color="#000066">100</font><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <font color="#000000"><b>constant</b></font>&nbsp;<font color="#7777cc"><b>integer</b></font>&nbsp;<span style="background-color: #ffffff"><font color="#000000">H</font></span>=<font color="#000066">200</font><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <font color="#7777cc"><b>integer</b></font>&nbsp;<font color="#7777cc"><b>array</b></font>&nbsp;<span style="background-color: #ffffff"><font color="#000000">mat2</font></span>&nbsp;[<span style="background-color: #ffffff"><font color="#000000">W</font></span>][<span style="background-color: #ffffff"><font color="#000000">H</font></span>]<br>
<br>
&nbsp;&nbsp; <font color="#000000"><b>endglobals</b></font><br>
<br>
&nbsp;&nbsp; <font color="#000000"><b>function</b></font>&nbsp;<span style="background-color: #ffffff"><font color="#000000">test</font></span>&nbsp;<font color="#000000"><b>takes</b></font>&nbsp;<font color="#7777cc"><b>nothing</b></font>&nbsp;<font color="#000000"><b>returns</b></font>&nbsp;<font color="#7777cc"><b>nothing</b></font><br>
&nbsp;&nbsp;&nbsp;&nbsp;<font color="#000000"><b>local</b></font>&nbsp;<font color="#7777cc"><b>integer</b></font>&nbsp;<span style="background-color: #ffffff"><font color="#000000">i</font></span>=<font color="#000066">0</font><br>
&nbsp;&nbsp;&nbsp;&nbsp;<font color="#000000"><b>local</b></font>&nbsp;<font color="#7777cc"><b>integer</b></font>&nbsp;<span style="background-color: #ffffff"><font color="#000000">j</font></span>=<font color="#000066">0</font><br>
&nbsp;&nbsp;&nbsp;&nbsp;<font color="#000000"><b>local</b></font>&nbsp;<font color="#7777cc"><b>integer</b></font>&nbsp;<span style="background-color: #ffffff"><font color="#000000">c</font></span>=<font color="#000066">0</font><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <font color="#000000"><b>call</b></font>&nbsp;<span style="background-color: #ffffff"><font color="#000000">BJDebugMsg</font></span>(<span style="background-color: #ffffff"><font color="#000000">I2S</font></span>(<span style="background-color: #ffffff"><font color="#000000">mat1</font></span><font color="#000066">.</font><span style="background-color: #ffffff"><font color="#000000">size</font></span>)) <font color="#008800">//displays 200 (10 * 20)</font><br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <font color="#008800">//fill the array:</font><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <font color="#000000"><b>loop</b></font><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <font color="#000000"><b>exitwhen</b></font>&nbsp;(<span style="background-color: #ffffff"><font color="#000000">i</font></span>==<span style="background-color: #ffffff"><font color="#000000">mat1</font></span><font color="#000066">.</font><span style="background-color: #ffffff"><font color="#000000">width</font></span>)<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <font color="#000000"><b>set</b></font>&nbsp;<span style="background-color: #ffffff"><font color="#000000">j</font></span>=<font color="#000066">0</font><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <font color="#000000"><b>loop</b></font><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <font color="#000000"><b>exitwhen</b></font>&nbsp;(<span style="background-color: #ffffff"><font color="#000000">j</font></span>==<span style="background-color: #ffffff"><font color="#000000">mat1</font></span><font color="#000066">.</font><span style="background-color: #ffffff"><font color="#000000">height</font></span>)<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <font color="#000000"><b>set</b></font>&nbsp;<span style="background-color: #ffffff"><font color="#000000">c</font></span>=<span style="background-color: #ffffff"><font color="#000000">c</font></span>+<font color="#000066">1</font><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <font color="#000000"><b>set</b></font>&nbsp;<span style="background-color: #ffffff"><font color="#000000">mat1</font></span>[<span style="background-color: #ffffff"><font color="#000000">i</font></span>][<span style="background-color: #ffffff"><font color="#000000">j</font></span>]=<span style="background-color: #ffffff"><font color="#000000">c</font></span><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <font color="#000000"><b>set</b></font>&nbsp;<span style="background-color: #ffffff"><font color="#000000">j</font></span>=<span style="background-color: #ffffff"><font color="#000000">j</font></span>+<font color="#000066">1</font><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <font color="#000000"><b>endloop</b></font><br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <font color="#000000"><b>set</b></font>&nbsp;<span style="background-color: #ffffff"><font color="#000000">i</font></span>=<span style="background-color: #ffffff"><font color="#000000">i</font></span>+<font color="#000066">1</font><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <font color="#000000"><b>endloop</b></font><br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <font color="#000000"><b>call</b></font>&nbsp;<span style="background-color: #ffffff"><font color="#000000">BJDebugMsg</font></span>( <span style="background-color: #ffffff"><font color="#000000">I2S</font></span>( <span style="background-color: #ffffff"><font color="#000000">mat1</font></span>[<font color="#000066">0</font>][<font color="#000066">1</font>]&nbsp;&nbsp;)&nbsp;&nbsp;) <font color="#008800">//displays 2</font><br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <font color="#000000"><b>call</b></font>&nbsp;<span style="background-color: #ffffff"><font color="#000000">BJDebugMsg</font></span>( <span style="background-color: #ffffff"><font color="#000000">I2S</font></span>( <span style="background-color: #ffffff"><font color="#000000">mat2</font></span><font color="#000066">.</font><span style="background-color: #ffffff"><font color="#000000">width</font></span>) ) <font color="#008800">//displays 100</font><br>
&nbsp;&nbsp; <font color="#000000"><b>endfunction</b></font></font>

<h3 style="color: black"><a name="storstruct"></a>Structs with more index space</h3>

<p>We got a struct X:</p>

<pre>
<font color="#000000"><b>struct</b></font> <span style="background-color: #ffffff"><font color="#000000">X</font></span>
    <font color="#7777cc"><b>integer</b></font> <span style="background-color: #ffffff"><font color="#000000">a</font></span>
    <font color="#7777cc"><b>integer</b></font> <span style="background-color: #ffffff"><font color="#000000">b</font></span>
<font color="#000000"><b>endstruct</b></font>
</pre>

<p>For some reason, the 8190 instances limit is not enough for us, we need 10000 instances ! so:</p>

<pre>
<font color="#000000"><b>struct</b></font> <span style="background-color: #ffffff"><font color="#000000">X</font></span>[<font color="#000066">10000</font>]
    <font color="#7777cc"><b>integer</b></font> <span style="background-color: #ffffff"><font color="#000000">a</font></span>
    <font color="#7777cc"><b>integer</b></font> <span style="background-color: #ffffff"><font color="#000000">b</font></span>
<font color="#000000"><b>endstruct</b></font>
</pre>

<p>Not to be confused with an instance limit improvement, it is an improvement for index space, both terms are usually equivalent unless there are array members involved:</p>

<pre>
<font color="#000000"><b>struct</b></font> <span style="background-color: #ffffff"><font color="#000000">X</font></span>[<font color="#000066">10000</font>]
    <font color="#7777cc"><b>integer</b></font> <span style="background-color: #ffffff"><font color="#000000">a</font></span>[<font color="#000066">2</font>]
    <font color="#7777cc"><b>integer</b></font> <span style="background-color: #ffffff"><font color="#000000">b</font></span>[<font color="#000066">5</font>]
<font color="#000000"><b>endstruct</b></font>
</pre>

<p>This struct got a maximum instance count of 2000</p>

<p>You cannot specify index space enhancers on structs that extend other structs or interfaces.</p>

<pre>
<font color="#000000"><b>struct</b></font> <span style="background-color: #ffffff"><font color="#000000">X</font></span>[<font color="#000066">10000</font>] <font color="#000000"><b>extends</b></font> <span style="background-color: #ffffff"><font color="#000000">Y</font></span> <font color="#008800">//bad</font>
    <font color="#7777cc"><b>integer</b></font> <span style="background-color: #ffffff"><font color="#000000">a</font></span>[<font color="#000066">2</font>]
    <font color="#7777cc"><b>integer</b></font> <span style="background-color: #ffffff"><font color="#000000">b</font></span>[<font color="#000066">5</font>]
<font color="#000000"><b>endstruct</b></font>

<font color="#000000"><b>interface</b></font> <span style="background-color: #ffffff"><font color="#000000">A</font></span>[<font color="#000066">20000</font>] <font color="#008800">//good</font>
    <font color="#000000"><b>method</b></font> <span style="background-color: #ffffff"><font color="#000000">a</font></span> <font color="#000000"><b>takes</b></font> <font color="#7777cc"><b>nothing</b></font> <font color="#000000"><b>returns</b></font> <font color="#7777cc"><b>nothing</b></font>
<font color="#000000"><b>endinterface</b></font>

<font color="#000000"><b>struct</b></font> <span style="background-color: #ffffff"><font color="#000000">B</font></span> <font color="#000000"><b>extends</b></font> <span style="background-color: #ffffff"><font color="#000000">A</font></span>
    <font color="#000000"><b>method</b></font> <span style="background-color: #ffffff"><font color="#000000">a</font></span> <font color="#000000"><b>takes</b></font> <font color="#7777cc"><b>nothing</b></font> <font color="#000000"><b>returns</b></font> <font color="#7777cc"><b>nothing</b></font>
       <font color="#000000"><b>call</b></font> <span style="background-color: #ffffff"><font color="#000000">BJDebugMsg</font></span>(<font color="#0000cc"><i>"..."</i></font>)
    <font color="#000000"><b>endmethod</b></font>
<font color="#000000"><b>endstruct</b></font>

<font color="#000000"><b>struct</b></font> <span style="background-color: #ffffff"><font color="#000000">C</font></span>[<font color="#000066">20000</font>] <font color="#008800">//good</font>
    <font color="#7777cc"><b>integer</b></font> <span style="background-color: #ffffff"><font color="#000000">x</font></span>
<font color="#000000"><b>endstruct</b></font>

<font color="#000000"><b>struct</b></font> <span style="background-color: #ffffff"><font color="#000000">D</font></span> <font color="#000000"><b>extends</b></font> <span style="background-color: #ffffff"><font color="#000000">C</font></span>
    <font color="#7777cc"><b>integer</b></font> <span style="background-color: #ffffff"><font color="#000000">y</font></span>
<font color="#000000"><b>endstruct</b></font>
</pre>

<p>Notice that A,B,C and D got a limit of 20000 indexes.</p>

<p>It is a little different for array structs, since as you can see, you cannot use the [] storage size specifier and extends at the same time. Since 0.9.E.1, it is possible to use array structs with enhanced storage specifying the size after the array keyword:</p>

<pre><font color="#000000"><b>struct</b></font>&nbsp;<span style="background-color: #ffffff"><font color="#000000">aBigOne</font></span>&nbsp;<font color="#000000"><b>extends</b></font>&nbsp;<font color="#7777cc"><b>array</b></font>&nbsp;[ <font color="#000066">20000</font>]
&nbsp;&nbsp; <font color="#7777cc"><b>integer</b></font>&nbsp;<span style="background-color: #ffffff"><font color="#000000">a</font></span>
&nbsp;&nbsp; <font color="#7777cc"><b>integer</b></font>&nbsp;<span style="background-color: #ffffff"><font color="#000000">b</font></span>
&nbsp;&nbsp; <font color="#7777cc"><b>integer</b></font>&nbsp;<span style="background-color: #ffffff"><font color="#000000">c</font></span>
<font color="#000000"><b>endstruct</b></font>

<font color="#000000"><b>function</b></font>&nbsp;<span style="background-color: #ffffff"><font color="#000000">meh</font></span>&nbsp;<font color="#000000"><b>takes</b></font>&nbsp;<font color="#7777cc"><b>nothing</b></font>&nbsp;<font color="#000000"><b>returns</b></font>&nbsp;<font color="#7777cc"><b>nothing</b></font>
&nbsp;&nbsp; <font color="#000000"><b>set</b></font>&nbsp;<span style="background-color: #ffffff"><font color="#000000">aBigOne</font></span><font color="#000066">[19990].</font><span style="background-color: #ffffff"><font color="#000000">a</font></span>&nbsp;= <font color="#000066">12</font>
<font color="#000000"><b>endfunction</b></font>
</pre>

<h3 style="color: black"><a name="stordyrar"></a>Dynamic arrays with more index space</h3>

<p>Dynamic arrays already use [] to specify the size for each instance, but what if you want to specify the maximum storage space? I was forced to add a comma:</p>

<pre>
<font color="#000000"><b>type</b></font> <span style="background-color: #ffffff"><font color="#000000">myDyArray</font></span> <font color="#000000"><b>extends</b></font> <font color="#7777cc"><b>integer</b></font> <font color="#7777cc"><b>array</b></font> [<font color="#000066">200</font>] <font color="#008800">//a normal dynamic array type of size 200</font>
                                           <font color="#008800">//max 40 instances</font>


<font color="#000000"><b>type</b></font> <span style="background-color: #ffffff"><font color="#000000">myDyArray</font></span> <font color="#000000"><b>extends</b></font> <font color="#7777cc"><b>integer</b></font> <font color="#7777cc"><b>array</b></font> [<font color="#000066">200</font>,<font color="#000066">40000</font>] <font color="#008800">//an enhanced dynamic array type of size 200</font>
                                                 <font color="#008800">//max 200 instances</font>

</pre>

<h3 style="color: black">Jass Syntax extensions</h3>

<h4 style="color: black"><a name="secolon"></a>Colon</h4>

<p>This is a new operator that basically allows you to use [] differently, call it a reverse []. Sometimes the logic of a script requires the order to be different in order to make more sense.</p>

<pre><font color="#000000"><b>function</b></font> <span style="background-color: #ffffff"><font color="#000000">test</font></span> <font color="#000000"><b>takes</b></font> <font color="#7777cc"><b>nothing</b></font> <font color="#000000"><b>returns</b></font> <font color="#7777cc"><b>nothing</b></font>
 <font color="#000000"><b>local</b></font> <font color="#7777cc"><b>integer</b></font> <span style="background-color: #ffffff"><font color="#000000">a</font></span>=<font color="#000066">3</font>
 <font color="#000000"><b>local</b></font> <font color="#7777cc"><b>integer</b></font> <font color="#7777cc"><b>array</b></font> <span style="background-color: #ffffff"><font color="#000000">X</font></span>

    <font color="#000000"><b>set</b></font> <span style="background-color: #ffffff"><font color="#000000">X</font></span>[<span style="background-color: #ffffff"><font color="#000000">a</font></span>]=<font color="#000066">10</font> <font color="#008800">//both of these statements do the same</font>
    <font color="#000000"><b>set</b></font> <span style="background-color: #ffffff"><font color="#000000">a</font></span>:<span style="background-color: #ffffff"><font color="#000000">X</font></span> =<font color="#000066">10</font>

    <font color="#000000"><b>set</b></font> <span style="background-color: #ffffff"><font color="#000000">X</font></span>[<span style="background-color: #ffffff"><font color="#000000">a</font></span>] = <span style="background-color: #ffffff"><font color="#000000">X</font></span>[<span style="background-color: #ffffff"><font color="#000000">a</font></span>] + <font color="#000066">10</font> <font color="#008800">//The same.</font>
    <font color="#000000"><b>set</b></font> <span style="background-color: #ffffff"><font color="#000000">a</font></span>:<span style="background-color: #ffffff"><font color="#000000">X</font></span> = <span style="background-color: #ffffff"><font color="#000000">a</font></span>:<span style="background-color: #ffffff"><font color="#000000">X</font></span> +<font color="#000066">10</font> 

    <font color="#000000"><b>set</b></font> <span style="background-color: #ffffff"><font color="#000000">X</font></span>[<font color="#000066">3</font>]=<font color="#000066">1000</font>
    <font color="#000000"><b>set</b></font> <font color="#000066">3</font>:<span style="background-color: #ffffff"><font color="#000000">X</font></span> =<font color="#000066">1000</font> <font color="#008800">//this is invalid syntax, sorry, only use : on variables and stuff like that.</font>

<font color="#000000"><b>endfunction</b></font>
</pre>

<h4 style="color: black"><a name="delicom"></a>Delimited comments</h4>

<p>These are the typical /* ... */ comments, that you can use to comment out blocks of code not necessarily ending with a line break. These comments are then just deleted from the map script. You can also nest these comments and do funny things as well...</p>
<br>
<font face="monospace"><font color="#008800">/* Delimited comments example</font><br>
<font color="#008800">&nbsp;They are a lot more useful than normal </font><br>
<font color="#008800">&nbsp;comments, really</font><br>
<br>
<font color="#008800">&nbsp;*/</font><br>
<font color="#000000"><b>function</b></font>&nbsp;<span style="background-color: #ffffff"><font color="#000000">test</font></span>&nbsp;<font color="#000000"><b>takes</b></font>&nbsp;<font color="#7777cc"><b>nothing</b></font>&nbsp;<font color="#000000"><b>returns</b></font>&nbsp;<font color="#7777cc"><b>nothing</b></font><br>
&nbsp;&nbsp;&nbsp;&nbsp;<font color="#000000"><b>call</b></font>&nbsp;<span style="background-color: #ffffff"><font color="#000000">Something</font></span>( <font color="#008800">/*5*/</font>&nbsp;<font color="#000066">66</font>) <font color="#008800">/*We temporarily commented out 5, and replaced it with 66*/</font><br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;<font color="#008800">/*</font><br>
<font color="#008800">&nbsp;&nbsp;&nbsp;&nbsp;call Something( /*5*/ 66)</font><br>
<font color="#008800">&nbsp;&nbsp;&nbsp;&nbsp;*/</font><br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;<font color="#008800">// That comment up there contains another delimited comment... /*</font><br>
&nbsp;&nbsp;&nbsp;&nbsp;<font color="#000000"><b>call</b></font>&nbsp;<span style="background-color: #ffffff"><font color="#000000">BJDebugMsg</font></span>(<font color="#0000cc"><i>"Notice how the previous comment start was ignored"</i></font>&nbsp;+ <font color="#008800">/*</font><br>
<font color="#008800">&nbsp;&nbsp;&nbsp;&nbsp;*/</font>+<font color="#0000cc"><i>"because it was inside a 'normal' comment "</i></font>+<font color="#008800">/*</font><br>
<font color="#008800">&nbsp;&nbsp;&nbsp;&nbsp;*/</font>+<font color="#0000cc"><i>"Also notice how we made the parser skipped the previous "</i></font>+<font color="#008800">/*</font><br>
<font color="#008800">&nbsp;&nbsp;&nbsp;&nbsp;*/</font>+<font color="#0000cc"><i>"line breaks because they were inside a comment"</i></font>+<font color="#008800">/*</font><br>
<font color="#008800">&nbsp;&nbsp;&nbsp;&nbsp;*/</font><font color="#0000cc"><i>"These comments do not count if they are /*inside a string*/ ... "</i></font>)<br>
<br>
<br>
<font color="#000000"><b>endfunction</b></font></font><br>
<br>
<br>
<br>
<br>
&nbsp;
<h3 style="color: black"><a name="hook"></a>hook</h3>

<p>There are functions that are outside of our control most of the times, like natives and those in blizzard.j. The <strong>hook</strong> keyword allows us to detect them.</p>

<p>Use hook, the name of the native/bj function and the name of a function or static method and you will be able to detect when that native is called and also capture the arguments given to it.</p>
<font face="monospace"> <font color="#000000"><b>function</b></font>&nbsp;<span style="background-color: #ffffff"><font color="#000000">onRemoval</font></span>&nbsp;<font color="#000000"><b>takes</b></font>&nbsp;<font color="#7777cc"><b>unit</b></font>&nbsp;<span style="background-color: #ffffff"><font color="#000000">u</font></span>&nbsp;<font color="#000000"><b>returns</b></font>&nbsp;<font color="#7777cc"><b>nothing</b></font><br>
&nbsp;&nbsp;&nbsp;&nbsp;<font color="#000000"><b>call</b></font>&nbsp;<span style="background-color: #ffffff"><font color="#000000">BJDebugMsg</font></span>(<font color="#0000cc"><i>"unit is being removed!"</i></font>)<br>
<font color="#000000"><b>endfunction</b></font><br>
<br>
<font color="#000000"><b>struct</b></font>&nbsp;<span style="background-color: #ffffff"><font color="#000000">err</font></span><br>
&nbsp;&nbsp;&nbsp;&nbsp;<font color="#000000"><b>static</b></font>&nbsp;<font color="#000000"><b>method</b></font>&nbsp;<span style="background-color: #ffffff"><font color="#000000">onrem</font></span>&nbsp;<font color="#000000"><b>takes</b></font>&nbsp;<font color="#7777cc"><b>unit</b></font>&nbsp;<span style="background-color: #ffffff"><font color="#000000">u</font></span>&nbsp;<font color="#000000"><b>returns</b></font>&nbsp;<font color="#7777cc"><b>nothing</b></font>&nbsp;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <font color="#000000"><b>call</b></font>&nbsp;<span style="background-color: #ffffff"><font color="#000000">BJDebugMsg</font></span>(<font color="#0000cc"><i>"This also knows that a unit is being removed!"</i></font>)<br>
&nbsp;&nbsp;&nbsp;&nbsp;<font color="#000000"><b>endmethod</b></font><br>
<font color="#000000"><b>endstruct</b></font><br>
<br>
<font color="#000000"><b>hook</b></font>&nbsp;<span style="background-color: #ffffff"><font color="#000000">RemoveUnit</font></span>&nbsp;<span style="background-color: #ffffff"><font color="#000000">onRemoval</font></span><br>
<font color="#000000"><b>hook</b></font>&nbsp;<span style="background-color: #ffffff"><font color="#000000">RemoveUnit</font></span>&nbsp;<span style="background-color: #ffffff"><font color="#000000">err</font></span><font color="#000066">.</font><span style="background-color: #ffffff"><font color="#000000">onrem</font></span>&nbsp;<font color="#008800">//works as well</font></font><br>
<br>
&nbsp;
<p>Try the code in some map, in which RemoveUnit is called sometimes and see what happens next time it is called.</p>

<p>There are some limitations for now, if the native/bj function is called by another bj function, the hook does not work when that other bj function gets called.</p>

<h3 style="color: black"><a name="inject"></a>inject</h3>

<p>Certain advanced users might use the world editor yet prefer to have more control over the map script, namely making their own main or config functions, the inject preprocessors allows to replace such functions.</p>

<p>The syntax is: //! inject main/config (...) //! endinject</p>

<p>For 例子</p>

<pre>
<font color="#777777">//! inject main</font>
   <font color="#008800">//some function calls may go here</font>

   <font color="#008800">// this places vjass initializations there, notice structs are first initialized then library initializers</font>
   <font color="#008800">// are called</font>
   <font color="#777777">//! dovjassinit</font>


   <font color="#008800">//other calls may go here</font>

   <font color="#000000"><b>call</b></font> <span style="background-color: #ffffff"><font color="#000000">InitCustomTriggers</font></span>() <font color="#008800">//maybe you want to exploit that world editor function...</font>
<font color="#777777">//! endinject</font>



</pre>

<p>The dovjassinit preprocessor may prove very helpful, it is only necessary if there is no call to InitBlizzard in the custom main or if you need to control the position of such initializing of structs and libraries.</p>

<p>//! inject config works the same way only that there is no //! dovjassinit for that case.</p>

<h3 style="color: black"><a name="slk"></a>Loading structs from SLK files</h3>

<p>It is possible to load (convert) an slk into code to be added to the map's script, specifically struct assigments. This can be really useful when a system uses structs to store data, since SLK is a table format it can save some work and make things easier to edit without the manual struct assigning.</p>

<p>The preprocessor to load an slk file is //! loaddata "path.slk" . The file path argument follows exactly the same rules as the ones I already specified in import (including lookup folders)</p>

<p>Both the slk and the struct type to be loaded need to follow very specific rules.</p>

<h4 style="color: black">The SLK</h4>

<p>The SLK file requires to have an struct name at (row 1, column 1) Then the first row contains field names, the next rows contain a [key] and values for the names specified up there.</p>

<table border="1" cellpadding="5">
	<tbody>
		<tr>
			<td>stname</td>
			<td>this</td>
			<td>is</td>
			<td>just</td>
			<td>an</td>
			<td>example</td>
		</tr>
		<tr>
			<td>1</td>
			<td>2</td>
			<td>3</td>
			<td>4</td>
			<td>5</td>
			<td>6</td>
		</tr>
		<tr>
			<td>7</td>
			<td>8</td>
			<td>9</td>
			<td>10</td>
			<td>11</td>
			<td>12</td>
		</tr>
	</tbody>
</table>

<p>In the example, the name of the struct type to be loaded is stname, the keys of the instances that will be loaded are 1 and 7, and the rest is information about fields and values.</p>

<h4 style="color: black">The struct type</h4>

<p>The struct type to be used (in the example, stname) requires a getFromKey static method that returns a value of the struct type.</p>

<p>getFromKey() would simply convert a key value and return an equivalent struct, this is because you often want data structs to be related to something else. (Most of the times the [something else] will be an object id.)</p>

<p>For this example, getFromKey would have to take an integer value</p>

<p>The struct type also requires to have the fields declared in the SLK file, the SLK is not forced to list all the fields of the struct type.</p>

<p>So if we have this struct definition:</p>

<pre><span class="syntax0"><span class="syntax-KEYWORD2">struct</span> stname
    <span class="syntax-KEYWORD3">integer</span> <span class="syntax-LITERAL2">this</span>
    <span class="syntax-KEYWORD3">integer</span> is
    <span class="syntax-KEYWORD3">integer</span> just
    <span class="syntax-KEYWORD3">integer</span> an
    <span class="syntax-KEYWORD3">integer</span> example

    <span class="syntax-KEYWORD2">static</span> stname <span class="syntax-KEYWORD3">array</span> values

    <span class="syntax-KEYWORD2">static</span> <span class="syntax-KEYWORD2">method</span> getFromKey <span class="syntax-KEYWORD2">takes</span> <span class="syntax-KEYWORD3">integer</span> i <span class="syntax-KEYWORD2">returns</span> <span class="syntax-KEYWORD3">thistype</span>
        <span class="syntax-KEYWORD1">if</span> <span class="syntax-OPERATOR">(</span>stname<span class="syntax-OPERATOR">.</span>values<span class="syntax-OPERATOR">[</span>i<span class="syntax-OPERATOR">]</span><span class="syntax-OPERATOR">=</span><span class="syntax-OPERATOR">=</span><span class="syntax-DIGIT">0</span><span class="syntax-OPERATOR">)</span> <span class="syntax-KEYWORD1">then</span>
            <span class="syntax-KEYWORD1">set</span> values<span class="syntax-OPERATOR">[</span>i<span class="syntax-OPERATOR">]</span><span class="syntax-OPERATOR">=</span>stname<span class="syntax-OPERATOR">.</span><span class="syntax-KEYWORD4">create</span><span class="syntax-OPERATOR">(</span><span class="syntax-OPERATOR">)</span>
        <span class="syntax-KEYWORD1">endif</span>
     <span class="syntax-KEYWORD1">return</span> stname<span class="syntax-OPERATOR">.</span>values<span class="syntax-OPERATOR">[</span>i<span class="syntax-OPERATOR">]</span>
    <span class="syntax-KEYWORD2">endmethod</span>

<span class="syntax-KEYWORD2">endstruct</span>
</span></pre>

<p>And we also load the SLK from the previous example, the loaded init code would be:</p>

<pre>    <font color="#000000"><b>set</b></font> <span style="background-color: #ffffff"><font color="#000000">s</font></span>=<span style="background-color: #ffffff"><font color="#000000">stname</font></span><font color="#000066">.</font><span style="background-color: #ffffff"><font color="#000000">getFromKey</font></span>(<font color="#000066">1</font>)
    <font color="#000000"><b>set</b></font> <span style="background-color: #ffffff"><font color="#000000">s</font></span><font color="#000066">.</font><font color="#000066">this</font>=<font color="#000066">2</font>
    <font color="#000000"><b>set</b></font> <span style="background-color: #ffffff"><font color="#000000">s</font></span><font color="#000066">.</font><span style="background-color: #ffffff"><font color="#000000">is</font></span>=<font color="#000066">3</font>
    <font color="#000000"><b>set</b></font> <span style="background-color: #ffffff"><font color="#000000">s</font></span><font color="#000066">.</font><span style="background-color: #ffffff"><font color="#000000">just</font></span>=<font color="#000066">4</font>
    <font color="#000000"><b>set</b></font> <span style="background-color: #ffffff"><font color="#000000">s</font></span><font color="#000066">.</font><span style="background-color: #ffffff"><font color="#000000">an</font></span>=<font color="#000066">5</font>
    <font color="#000000"><b>set</b></font> <span style="background-color: #ffffff"><font color="#000000">s</font></span><font color="#000066">.</font><span style="background-color: #ffffff"><font color="#000000">example</font></span>=<font color="#000066">6</font>
    <font color="#000000"><b>set</b></font> <span style="background-color: #ffffff"><font color="#000000">s</font></span>=<span style="background-color: #ffffff"><font color="#000000">stname</font></span><font color="#000066">.</font><span style="background-color: #ffffff"><font color="#000000">getFromKey</font></span>(<font color="#000066">7</font>)
    <font color="#000000"><b>set</b></font> <span style="background-color: #ffffff"><font color="#000000">s</font></span><font color="#000066">.</font><font color="#000066">this</font>=<font color="#000066">8</font>
    <font color="#000000"><b>set</b></font> <span style="background-color: #ffffff"><font color="#000000">s</font></span><font color="#000066">.</font><span style="background-color: #ffffff"><font color="#000000">is</font></span>=<font color="#000066">9</font>
    <font color="#000000"><b>set</b></font> <span style="background-color: #ffffff"><font color="#000000">s</font></span><font color="#000066">.</font><span style="background-color: #ffffff"><font color="#000000">just</font></span>=<font color="#000066">10</font>
    <font color="#000000"><b>set</b></font> <span style="background-color: #ffffff"><font color="#000000">s</font></span><font color="#000066">.</font><span style="background-color: #ffffff"><font color="#000000">an</font></span>=<font color="#000066">11</font>
    <font color="#000000"><b>set</b></font> <span style="background-color: #ffffff"><font color="#000000">s</font></span><font color="#000066">.</font><span style="background-color: #ffffff"><font color="#000000">example</font></span>=<font color="#000066">12</font>
</pre>

<p>Notice that this code is then run after the struct and libraries initialization</p>

<p>For a more practical explanation check out the SLK demo included in the JassHelper distribution.</p>

<h3 style="color: black"><a name="opt"></a>Script optimization</h3>

<p>Since version 0.9.A.0 script optimization is available in jasshelper, it is currently enabled by default, in order to disable optimization you can either enable debug mode or use the --nooptimize argument (jasshelper.exe), newgen should get a menu entry for toggling this option added soon.</p>

<p>At the moment the only available optimization is function inlining. More methods shall be added later including some improved versions of some of wc3mapoptimizer's options.</p>

<h4 style="color: black"><a name="inl"></a>Function inlining</h4>

<p>Function inlining will look for function calls that can be inlined and then just convert their calls to a direct usage of the function's contents. In order not to break the normal execution of the map, this is done only in few cases. An example of inlining follows.</p>

<pre><font color="#000000"><b>function</b></font> <span style="background-color: #ffffff"><font color="#000000">MyFunction</font></span> <font color="#000000"><b>takes</b></font> <font color="#7777cc"><b>integer</b></font> <span style="background-color: #ffffff"><font color="#000000">a</font></span>, <font color="#7777cc"><b>integer</b></font> <span style="background-color: #ffffff"><font color="#000000">b</font></span> <font color="#000000"><b>returns</b></font> <font color="#7777cc"><b>integer</b></font>
    <font color="#000000"><b>return</b></font> <span style="background-color: #ffffff"><font color="#000000">myarray</font></span>[<span style="background-color: #ffffff"><font color="#000000">a</font></span>]*<span style="background-color: #ffffff"><font color="#000000">b</font></span>
<font color="#000000"><b>endfunction</b></font>

<font color="#000000"><b>function</b></font> <span style="background-color: #ffffff"><font color="#000000">MyOtherFunction</font></span> <font color="#000000"><b>takes</b></font> <font color="#7777cc"><b>nothing</b></font> <font color="#000000"><b>returns</b></font> <font color="#7777cc"><b>integer</b></font>
    <font color="#000000"><b>return</b></font> <span style="background-color: #ffffff"><font color="#000000">MyFunction</font></span>(<font color="#000066">3</font>,<font color="#000066">4</font>)
<font color="#000000"><b>endfunction</b></font>

<font color="#008800">//becomes:</font>

<font color="#000000"><b>function</b></font> <span style="background-color: #ffffff"><font color="#000000">MyOtherFunction</font></span> <font color="#000000"><b>takes</b></font> <font color="#7777cc"><b>nothing</b></font> <font color="#000000"><b>returns</b></font> <font color="#7777cc"><b>integer</b></font>
    <font color="#000000"><b>return</b></font> <span style="background-color: #ffffff"><font color="#000000">myarray</font></span>[<font color="#000066">3</font>]*<font color="#000066">4</font>
<font color="#000000"><b>endfunction</b></font>

</pre>

<p>Inlining is important because it will reduce the number of function calls and make certain parts of the map script faster, while at the same time it will allow you to write readable code.</p>

<p>How to make a function inlineable? The current algorithm basically follows these rules (which are subject to change to allow more functions to be considered inlineable in the future):</p>

<ul>
	<li>The function is a one-liner</li>
	<li>If the function is called by <strong>call</strong> the function's contents must begin with <strong>set</strong> or <strong>call</strong> or be a <strong>return</strong> of a single function.</li>
	<li>If the inlined function is an assigment (<strong>set</strong>) it should not assign one of its arguments.</li>
	<li>Every argument must be evaluated once and only once by the function, in the same order as they appear in the arguments list.</li>
	<li>If the function contains function calls, they should all be evaluated after the arguments UNLESS the function is marked as non-state changing, at the moment some very few native functions and also return bug exploiters are considered as non-state changing.</li>
</ul>

<h3 style="color: black"><a name="ext"></a>External Tools</h3>

<p>JassHelper allows the //! external preprocessor that let you call other tools on the map after the map is compiled with JassHelper, this way these tools may work the same with grimoire and WEHelper</p>

<p>The preprocessor is //! external EXTERNAL_TOOL_NAME [external arguments]</p>

<p>EXTERNAL_TOOL_NAME must match the name of the tool in the configuration (Either the dialog in the wehelper plugin or the .conf file for the grimoire version)</p>

<p>The text after the external name is optional and is given to the tool as command line arguments.</p>

<p>You may also use the externalblock preprocessor if you want to specify an input that will be send to the external tool in stdin:</p>
<font face="monospace"> <font color="#666666">//! externalblock EXTERNALNAME ARGUMENTS LIST</font><br>
<font color="#666666">//! i These lines will get send to</font><br>
<font color="#666666">//! i The tool as stdin</font><br>
<font color="#666666">//! i The i and the space after the i are ignored.</font><br>
&nbsp;&nbsp;<br>
&nbsp;&nbsp;&nbsp;&nbsp; <font color="#008800">//comment and whitespace not to appear in stdin</font><br>
<br>
<font color="#666666">//! i</font><br>
<font color="#666666">//! i That one up there was just an empty line to send to the program</font><br>
<font color="#666666">//! endexternalblock</font></font>

<p>What if the tool supports not stdin but a file? Well, you can make jasshelper save the contents of externalblock in a temp file and then send that file to the tool using $FILENAME$</p>
<font face="monospace"> <font color="#666666">//! externalblock EXTERNALNAME SOME_ARGUMENTS $FILENAME$ OTHER_ARGUMENTS</font></font>

<p>If you try this you will find out that some tool makers out there for some strange reason require you to use specific extensions for the provided file names. Well, in that case you may use extension=</p>
<font face="monospace"> <font color="#666666">//! externalblock extension=lua OBJECTMERGER SOME_ARGUMENTS $FILENAME$ OTHER_ARGUMENTS</font></font>

<p>The next is kind of a section for programmers:</p>

<h4 style="color: black">What kind of tool?</h4>

<p>For a tool to work correctly with the external preprocessor it must have a very specific behaviour.</p>

<p>First of all JassHelper will pass these arguments to the tool</p>

<ul>
	<li>The map's file path.</li>
	<li>A tokenized chain of directory paths ( c:/;d:/somepath;c:/anotherlocation/ ) These are the lookup paths used by JassHelper, in order to fix some issues the \ character is replaced with / here.</li>
	<li>The rest of the line in the external preprocessor. (The tool might or might not have more arguments)</li>
</ul>

<p>Then the tool must use the 0 code if it was succesful, otherwise return any number different to 0 and should write an error message to either stdin or stderr.</p>

<h3 style="color: black"><a name="br"></a>Linebreak fixer.</h3>

<p>As a side effect of the parsing necessary for this project it also replaces line breaks inside Jass string literals into properly escaped \n this also fixes an issue with PJass giving the wrong line number if there are strings with linebreaks.</p>
<a name="inst"></a>

<h2 style="color: black">II. Installation</h2>
<a name="platplat"></a>

<h3 style="color: black">* Supported platforms</h3>

<p>This program is currently developped for windows XP SP2, WINE 1.0 (or greater) . It probably works well on older versions of windows in wich warcraft III also runs. Windows XP SP3 probably works as well. It might work on vista but there is no testing for that OS or ability to debug there. Please, notice that though you are able to run in platforms other than windows XP and WINE&gt;=1.0 I might not able to fix bugs you report in them that I cannot reproduce in XP or WINE.</p>

<h3 style="color: black">* Jass New Gen Pack</h3>

<p>Jass New Gen Pack already comes with JassHelper, although it might not come with the most recent version, in order to update you can simply copy executable\jasshelper.exe to the NewGen Pack"s jasshelper subfolder. You may also update the JassHelper documentation if you wish</p>

<p>It is suggested that you install new gen pack first and then update jasshelper, it may be the case that newgen pack's jasshelper holds the same version of jasshelper then it would not be necessary to update.</p>

<p>In order to get Jass New Gen Pack visit: <a href="http://www.wc3campaigns.net/showthread.php?t=90999">http://www.wc3campaigns.net/showthread.php?t=90999</a></p>

<h3 style="color: black">* WEHelper Plugin</h3>

<p>I decided to stop including the WEHelper plugin in jasshelper's distribution package. If you still use WEHelper you should consider moving to newgen, else you can request me the .dll file for jasshelper. You may also make your own WEHelper plugin and make it use the standalone jasshelper.exe to compile the map. Or you can compile the .DLL file from the sourcecode if you have a delphi compiler.</p>

<h3 style="color: black">* Grimoire</h3>

<p>You need <a href="http://www.wc3campaigns.net/showthread.php?t=86652">grimoire 1.2 or greater</a> which includes wehack.dll. Then you have to copy executable\jasshelper.exe to a jasshelper subfolder in grimoire's folder. You also need <a href="http://www.wc3campaigns.net/showthread.php?t=75239">pJass</a>, locate pJass.exe on grimoire's folder as well. As of grimoire 1.2 you may have to update wehack.lua yourself or wait for a newer grimoire version that will be compatible with the new way jasshelper works.</p>

<p>You will have to copy SFMPQ.dll to the jasshelper folder</p>

<h3 style="color: black">* Standalone</h3>

<p>executable\jasshelper.exe may also work as an standalone compiler, you require bin\SFMPQ.dll and pjass in the same folder (notice SFMPQ.dll needs to be inside a subfolder called bin), after that simply refer to the command line subsection in the usage section.</p>

<p>If you are gonna call jasshelper.exe from another tool, notice that jasshelper will create and use logs and backups subfolders inside its work folder. jasshelper.conf has priority in the work folder and if it is not found the one in jasshelper's folder is gonna be created and used.</p>
<a name="usag"></a>

<h2 style="color: black">III. Usage</h2>
<a name="usagnewg"></a>

<h3 style="color: black">* Newgen Pack</h3>

<p>After installing the new jasshelper executable, just open Newgen World Editor as usual, it should now call the new jasshelper version. In order to know more about newgen's jasshelper menu you should probably take a look to newgen's readme file.</p>

<h3 style="color: black">* Grimoire</h3>

<p>Simply use we.bat to run grimoire, then you'd have to disable the syntax checker and enable the map compiler using the grimoire menus. To use debug mode simply use compiler\compiler debug mode.</p>

<p>Currently, compiler is not called when using testmap, so you must save the map before using the testmap button.</p>
<a name="usagnewg"></a>

<h3 style="color: black">Command line</h3>

<p>jasshelper.exe combined with the sfmpq.dll and pjass is able to compile maps without any aid from an editor hack, you might want to know about this if you are on Linux (where WINE allows you to use WorldEditor and jasshelper but not grimoire) or for example if you cannot run grimoire for whatever reason.</p>

<p>The basic command line syntax is:</p>

<pre>jasshelper.exe &lt;path_to_common.j&gt; &lt;path_to_blizzard.j&gt; &lt;path_to_map.w3x&gt;</pre>

<p>This will make jasshelper to process the source map, and update the map with a new compiled script. You can extract common.j and blizzard.j from the scripts folder in war3patch.mpq.</p>

<p>If instead of three arguments you pass four file arguments to the program, the behavior changes:</p>

<pre>jasshelper.exe &lt;path_to_common.j&gt; &lt;path_to_blizzard.j&gt; &lt;path_to_mapscript.j&gt; &lt;path_to_map.w3x&gt; </pre>

<p>It will ignore the map's script file, and instead consider the given script file as the vJass source. Since the 3 files syntax removes the original vJass source code from the map, this method is more useful, you can generate the source map by exporting the map's script from the editor. (<strong>Hint:</strong> Use //! import and //! novjass in combination to command line jasshelper and World Editor)</p>

<p>Of course, that is not enough flexibility, so jasshelper supports a couple of options you can place before the path to blizzard.j:</p>

<ul>
	<li><a name="clidebug"></a><b>--debug</b> : This flag will make jasshelper compile in debug mode (more information in the quite extense vJass section). It also turns --nooptimize on.</li>
	<li><a name="clinopre"></a><b>--nopreprocessor</b> : If for some reason you just want to check normal Jass syntax, and call PJass using jasshelper as proxy, so you can use this option.</li>
	<li><a name="clinoop"></a><b>--nooptimize</b> : Disables optimization, refer to the <a href="#opt">script optimization</a> section for more information.</li>
	<li><a name="clifile"></a><b>--scriptonly</b> : This one changes the behavior of the next arguments, it forces you to provide four files:
	<pre>jasshelper.exe --scriptonly &lt;path_to_common.j&gt; &lt;path_to_blizzard.j&gt; &lt;path_to_input.j&gt; &lt;path_to_output.j&gt;</pre>
	<br>
	This syntax requires no map to be provided, will simply evaluate the input .j file and show syntax errors if necessary. If the compiling is successful, jasshelper will write the output script to the file path you provided.
	<p></p>
	</li>
	<li><a name="cliwar"></a><b>--warcity</b> : This setting will automatically turn --scriptonly on, it makes jasshelper evaluate the input script file as if it was a "warcity script file", WarCiTy is a program that converts a map's custom trigger data into a special sort of .j script. This setting will simply make jasshelper evaluate only the //! import and //! novjass preprocessors, it will also prevent the adition of guide comments specifying it just imported the file. There is no syntax checking feature for this mode.</li>
	<li><a name="clizinc"></a><b>--zinconly</b> : This setting will automatically turn --scriptonly on, it makes jasshelper evaluate the input script file assuming it is a single zinc source file. It will then output the compiled vJass code after the zinc phase.</li>
	<li><a name="climac"></a><b>--macromode</b> : Like warcity but also evaluates textmacros.</li>
	<li><a name="cliabout"></a><b>--about</b> : This just displays the about dialog (Do you want to know what jasshelper version you got?) Notice that it ignores the file arguments provided.</li>
	<li><a name="clierror"></a><b>--showerrors</b> : Shows the previous syntax error(s) (Without compiling).</li>
	<li><a name="clicli"></a><b>clijasshelper.exe</b> : clijasshelper.exe behaves exactly as jasshelper.exe but it does not use/need windows GUI, (it is still a windows-WINE app though), it may be useful sometimes (for example if you want to use jasshelper from a ssh sesion), it just outputs stuff to stdout, if for some reason stdout does not work, it will output to stdout.txt in the work folder.</li>
</ul>

<h2 style="color: black">IV. Updating</h2>

<p>Unless otherwise stated, the way to update jasshelper for newgen pack is to simply replace the executable file.</p>

<h2 style="color: black">IV. Uninstalling</h2>

<ul>
	<li>WEHelper plugin : Move JASSHelper.dll out of the plugins folder/delete it</li>
	<li>Newgen pack/grimoire: I think removing the jasshelper folder would make it notice it was uninstalled.</li>
	<li>From your computer: jasshelper does not use the registry, so you can just wipe the folder containing it.</li>
</ul>

<h2 style="color: black">VI. Credits and thanks</h2>

<ul>
	<li>The Gold parsing system assists in some of the most complex parsing involved: <a href="http://www.devincook.com/goldparser/">http://www.devincook.com/goldparser/</a></li>
	<li>pipedream: For a lot of help in deciding how the syntax additions would work. And having contributed so much to WE hacking.</li>
	<li>weaaddar: Clever allocation method used by structs and arrays.</li>
	<li>Zoxc : for making WEHelper.</li>
	<li>Vexorian : Just converted stuff inside his mind into this compiler.</li>
	<li>ZergLeb : Helped me fix an evil bug</li>
	<li>Grim001 : Bug reporting</li>
	<li>Anitarf : made me implement plenty of things he did not even use later. Help finding bugs.</li>
	<li>Rising_Dusk: delegate would not have been added without him.</li>
	<li>StealthOfKing : Helped fix SLK issues</li>
	<li>rain9441: found plenty of bugs with onDestroy in structs extending other structs.</li>
	<li>Captain Griffen, Here-b-Trollz, and some other people for bug reports.</li>
	<li>Alexander244: For using loaddata so much that the generated function is too large for PJass.</li>
	<li>Litany: Suggestions.</li>
	<li>Flame_phoenix: For making me figure out how necessary 2D arrays are and how hard to use the work aroudns were.</li>
	<li>C2H3NaO2: Bug reports</li>
	<li>Av3n: Provided his script file so I could fix a bug</li>
	<li>Zoxc and Deaod: , helping to fix some blizzard/common.j related issues.</li>
	<li>MindworX: Bug reports.</li>
	<li><a href="http://www.wc3c.net/" target="_blank">http://www.wc3c.net</a> Just wanted to put a link to my home site...</li>
	<li>I used gvim to generate most of this file <a href="http://www.vim.org/" target="_blank">http://www.vim.org/</a></li>
	<li>The Ultimate Packer for eXecutables : Copyright (c) 1996-2002 Markus Oberhumer &amp; Laszlo Molnar : <a href="http://upx.sourceforge.net/">http://upx.sourceforge.net</a> (though to be honest I do not use it anymore)</li>
</ul>

<h2 style="color: black">VII. Changelog</h2>

<ul>
	<li>0.A.2.B
	<ul>
		<li>Fixed a bug with static ifs that made them fail when the constant boolean variable had a comment in its declaration line.</li>
		<li>It is now possible to use . syntax inside a global/static member declaration. However, you must notice that this will not usually work unless you are calling a static member from a place bellow its declaraton . Else you would get a Pjass error.</li>
		<li>Array structs no longer 'declare' unusable allocate/deallocate methods. In other words, you may now use those method names when declaring a method inside an array struct.</li>
	</ul>
	</li>
	<li>0.A.2.A
	<ul>
		<li>Fixed a bug that allowed scope members to have invalid names and still compile.</li>
		<li>Fixed a bug that allowed natives and BJ to compile when given more arguments than necessary.</li>
		<li>_F, _I and _V do not get created anymore for array structs.</li>
		<li>Manual: Fixed the getFromKey example.</li>
		<li>Zinc: Fixed bugs that prevented some real literals to compile.</li>
		<li>Zinc: while(true) does not add a useless exitwhen(false).</li>
		<li>Zinc: Added do{..}while(..); .</li>
		<li>Zinc: You may now separate assignments with commas. These commas can be used in the for construct. In other words:<br>
		for ( x=0, y=0, z=0; x&lt;=10 &amp;&amp; y&lt;=10 &amp;&amp; z&lt;=10; x+=1, y+=x, z+=y) is now possible.</li>
	</ul>
	</li>
	<li>0.A.2.9
	<ul>
		<li>All module initializers run before any struct initializer.</li>
		<li>Fixed a bug that forbade comments after then in static ifs.</li>
		<li>Structname.methodName.exists should work outside static ifs.</li>
		<li>Static ifs should now work correctly with members/methods that are explicitly public or private. Note that private members/methods will not be visible to static ifs outside the struct.</li>
		<li>Zinc: Fixed random compile error bugs introduced in last version.</li>
	</ul>
	</li>
	<li>0.A.2.8
	<ul>
		<li>double import check now considers full path instead of just file name.</li>
		<li>static ifs can check if a method exists using .exists.</li>
		<li>private module destroy now works like module create (is not hidden from the implementing struct)</li>
		<li>Zinc: structs onInit and library onInit no longer conflict.</li>
	</ul>
	</li>
	<li>0.A.2.7
	<ul>
		<li>Added "comment" import mode.</li>
		<li>Added +=,/=,-=,/=, and for(assignment; condition; assignment) to Zinc.</li>
		<li>Fixed a bug with import doing a double import when given the same filename twice in OSes that use / instead of \</li>
		<li>Fixed a crash when attempting to use special methods like allocate for function interfaces, now it gives a syntax error...</li>
		<li>Fixed a bug with function literals not working correctly when the function returned a custom type.</li>
		<li>Fixed a bug with function interfaces not working correctly when they had themselves as argument/return value.</li>
		<li>Fixed a bug with //! import inside //! zinc tags</li>
		<li>Unclosed //! zinc tags inside a file will get reported.</li>
	</ul>
	</li>
	<li>0.A.2.6
	<ul>
		<li>externalblock now allows a $FILENAME$ argument and a extension= property.</li>
		<li>Fixed a bug that made /* */ comments mess up with the syntax error line number in the zinc/libraries phase when import was not used.</li>
		<li>Improved the library requirements error message.</li>
		<li>Zinc: Make [implement] cause syntax errors.</li>
	</ul>
	</li>
	<li>0.A.2.5
	<ul>
		<li>Limit of strings in a single line raised from 27 to 61.</li>
		<li>Zinc: Fix not being able to parse certain real literals.</li>
	</ul>
	</li>
	<li>0.A.2.4
	<ul>
		<li>Fixed a bug that allowed .getType() to cause jasshelper crashes.</li>
		<li>thistype works in static ifs. (not implicit though)</li>
		<li>When debug mode is on, static if phase will comment out lines instead of deleting them.</li>
		<li>Fixed a bug with optional requirements sometimes not working correctly.</li>
		<li>Zinc: jasshelper.conf's [noimplicitthis] option does not affect Zinc code.</li>
		<li>Fixed a bug with the shadow helper phase duplicating some comments.</li>
	</ul>
	</li>
	<li>0.A.2.3
	<ul>
		<li>Fixed a bug that made .exists cause obscure syntax errors.</li>
	</ul>
	</li>
	<li>0.A.2.2
	<ul>
		<li>Fixed a bug that prevented using .evalaute/ .execute on methods.</li>
		<li>Fixed a bug that caused syntax errors when you used a hook for a native that takes nothing.</li>
	</ul>
	</li>
	<li>0.A.2.1
	<ul>
		<li>.pointer has been removed from the syntax for using methods for function interfaces.</li>
		<li>You may now also use non-static methods for function interfaces (they are treated as functions that take an extra integer first)</li>
		<li>Zinc: Added anonymous methods.</li>
	</ul>
	</li>
	<li>0.A.2.0
	<ul>
		<li>Fixed some struct member declaration syntax errors appearing in line 1.</li>
		<li>Fixed a bug that made method.name return wrong values when using the method implicitely (without this).</li>
		<li>Fixed missing syntax error messages in the structs phase.</li>
		<li>Static Methods can be used as function pointers. Just do struct.method.pointer to get such function pointer. Implicit casting between methods and function interfaces will come later (so you do not have to use .pointer).</li>
		<li>Zinc: Allow anonymous functions in global / struct variable declarations.</li>
	</ul>
	</li>
	<li>0.A.0.1
	<ul>
		<li>Fixed some undefined code related to implicit this in member usage. Which could have caused very odd code to get generated.</li>
		<li>Fixed an old bug that sometimes added indentation and comments to syntax errors.</li>
		<li>Zinc: Fixed a random crash related to comments.</li>
		<li>Zinc: Fixed a lame mistake that made all of a zinc struct's members LIBRARY-private.</li>
	</ul>
	</li>
	<li>0.A.0.0
	<ul>
		<li>. or this. are not required anymore to use members. Note that this may cause issues if for some (incredibly weird) reason you try to use global variables from a method of a struct that has variables of the same name. To disable this feature, you can add [noimplicitthis] to jasshelper.conf.</li>
		<li>Improved the syntax error when you place a function inside a struct.</li>
		<li>Code values might get implicitly casted to boolexpr in some occasions, specifically, when using them as arguments for natives/bjfunc that take boolexpr. More cases will get added when type safety gets on its way for more stuff...</li>
		<li>Zinc: Added anonymous functions, but they cannot use locals from their parent (yet).</li>
		<li>Zinc: Fixed a crash that could happen when the zinc input is much smaller than the vJass output.</li>
		<li>Zinc: Fixed a couple of missing ; mistakes in the examples.</li>
	</ul>
	</li>
	<li>0.9.Z.5
	<ul>
		<li>Added externalblock.</li>
		<li>optional textmacros work.</li>
		<li>static ifs support elseif.</li>
		<li>static ifs support a struct's static constant booleans.</li>
		<li>Missing thens in static ifs are reported as a syntax error.</li>
		<li>Comments inside static ifs are deleted correctly when the condition is false.</li>
	</ul>
	</li>
	<li>0.9.Z.4
	<ul>
		<li>Reversed the deprecation of automatic method TriggerEvaluate, you may enable the syntax error adding [forcemethodevaluate] to jasshelper.conf.</li>
		<li>Added a syntax error when . and other unsupported operations are used in static ifs.</li>
		<li>Added a --zinconly command line argument that will just compile a zinc file into vJass code.</li>
		<li>Fixed a probable error with --macromode removing the first line of code.</li>
		<li>You may now use the identifier DEBUG_MODE as a constant boolean that is true if and only if debug mode is on.</li>
	</ul>
	</li>
	<li>0.9.Z.3
	<ul>
		<li>Correct operator precedence in structs phase, this change is not noticeable unless you had an overloaded == operator.</li>
		<li>structs phase's "Syntax Error" message is now slightly more detailed.</li>
		<li>You may now use a pair of decorative parenthesis in static ifs.</li>
		<li>custom operators used from above their declarion will once again use .evaluate automatically. (as it is not possible to do it manually).</li>
		<li>Hopefully fixed issues regarding using deallocate on child structs.</li>
		<li>Fixed a bug with deallocate requiring evaluate for no reason.</li>
		<li>Fixed a syntax error regression that happened when calling .destroy from above onDestroy.</li>
		<li>Zinc: When an if is all that is inside an else's contents, it is translated into elseif.</li>
		<li>Zinc: Compiler will try its best to keep comments, though it might place them in awkward positions...</li>
		<li>Zinc: Fixed a z.2 regression that made Zinc eat up parenthesis...</li>
	</ul>
	</li>
	<li>0.9.Z.2
	<ul>
		<li>Fixed a crash related to ==.</li>
		<li>Fixed a bug that for some reason required slks to have more than 2 columns, instead of more than 1...</li>
		<li>If a SLK value for a boolean member is 0 or 1, jasshelper will convert it into true or false.</li>
		<li>Added runtextmacro optional .</li>
		<li>.evaluate() is mandatory on methods if you want to call them from above their declaration</li>
		<li>to disable this new syntax error, add a [automethodevaluate] option to jasshelper.conf</li>
		<li>Zinc: Make grammar allow negating a negation.</li>
		<li>Zinc: A while's condition is compiled neatly, being able to avoid unnecessary not operators.</li>
	</ul>
	</li>
	<li>0.9.Z.1
	<ul>
		<li>Important: Removed virus that sneaked into some hidden folder inside the source tree.</li>
		<li>destroy can get replaced inside a struct.</li>
		<li>Added a deallocate method that works like allocate</li>
		<li>Added static versions of the name and name= operators.</li>
		<li>Added == overloading (and != for that matter)</li>
		<li>Zinc: add operator== to grammar.</li>
	</ul>
	</li>
	<li>0.9.Z.0
	<ul>
		<li>Added static ifs</li>
		<li>Added optional library requirements</li>
		<li>Added Zinc.</li>
	</ul>
	</li>
	<li>0.9.K.0
	<ul>
		<li>Variable shadowing is now part of correct vJass syntax. Compiler guarantees (or at least should) that there won't be global-local conflicts in the compiled jass code.</li>
	</ul>
	</li>
	<li>0.9.j.2
	<ul>
		<li>Fixed a memory out of bounds error related to some bugged native declaration usage.</li>
		<li>Fixed issues with undeclared variables and also array member leaks when you use array members on an interface and do not have onDestroy declared on one of its children.</li>
		<li>Fixed a bug with methods called the same as any function not being callable.</li>
	</ul>
	</li>
	<li>0.9.j.1
	<ul>
		<li>Removed returnfixer from the default, you may still toggle it on but it is not necessary anymore.</li>
		<li>Fixed some crashes in windows with non-cli jasshelper.</li>
	</ul>
	</li>
	<li>0.9.J.0
	<ul>
		<li>Jasshelper now comes with a phase that will do its best to fix return bug false positives at the cost of an extra function call. This is meant as a temporary fix while blizzard fixes the bugs caused by patch 1.24 , or you update your functions to avoid multiple return statements. This phase can be disabled through the config file. Check the updated manual for more info.</li>
	</ul>
	</li>
	<li>0.9.I.2
	<ul>
		<li>Fixed a bug with function hooks not working correctly if nothing else related to function interfaces is used by the map.</li>
		<li>Fixed a bug with function hooks not working correctly at all most of the time.</li>
		<li>The manual no longer wrongfully states that the order of execution of onInit methods is undefined (as it turns out it isn't).</li>
	</ul>
	</li>
	<li>0.9.I.1
	<ul>
		<li>Fixed a crash related to extends and array members.</li>
		<li>Fixed some chance that clijasshelper would attempt to create window.</li>
		<li>Fixed a bug with stub keywords causing childless struct not to call onDestroy correctly.</li>
		<li>Added hooks.</li>
		<li>It is more likely that methods using evaluate will not use TriggerEvaluate if they only call natives/blizzard.j functions.</li>
	</ul>
	</li>
	<li>0.9.I.0
	<ul>
		<li>Jasshelper can now support native declarations around the map script, and move them to the top of the script.</li>
	</ul>
	</li>
	<li>0.9.H.3
	<ul>
		<li>Added GetHandleId, StringHash, the gamecache Get and HaveStored natives and the hashtable Load and HaveSaved natives to the list of natives that do not modify the state. This means that functions that directly or indirectly call these natives are more likely to get inlined.</li>
		<li>Fixed a small typo bug inside a comment of sample jasshelper.conf .</li>
	</ul>
	</li>
	<li>0.9.H.2
	<ul>
		<li>Fixed a freeze and out of memory bug with mass storage arrays/structs/dynamic arrays when the storage size was greater than 8191*13.</li>
		<li>The mass storage arrays/structs/dynamic arrays picker functions will now take slightly less lines of code,</li>
	</ul>
	</li>
	<li>0.9.H.1
	<ul>
		<li>Fixed an off-by one error in the mass size arrays/structs/dynamic array code that caused various issues on boundary cases.</li>
		<li>jasshelper.conf can now determine the command line arguments given to the Jass syntax checker.</li>
		<li>Added key</li>
	</ul>
	</li>
	<li>0.9.H.0
	<ul>
		<li>Added block comments.</li>
		<li>If call InitBlizzard() is not found in the main function, jasshelper will add the initializing code to the end of the function, instead of raising an error</li>
	</ul>
	</li>
	<li>0.9.G.3
	<ul>
		<li>Fixed a crash when there were empty lines on some methods.</li>
		<li>Fixed a bug that prevented array structs from having static array members.</li>
		<li>Fixed private delegates/constants not working correctly inside modules (and possibly causing further bugs)</li>
		<li>Fixed problems related with clijasshelper not working in windows' cmd.exe.</li>
		<li>If for some bizare reason, there's no stdout assigned for clijasshelper, it will automatically send its output to stdout.txt.</li>
		<li>GetUnitUserData is now considered a non-state changing function by the inliner, which should increase the chances of functions that use it to get inlined.</li>
	</ul>
	</li>
	<li>0.9.G.2
	<ul>
		<li>Fixed a regression introduced in G.0 that caused various issues with function interfaces.</li>
		<li>Fixed "operators that return self" adding a chance to cause odd syntax errors, stack overflows and access violations.</li>
	</ul>
	</li>
	<li>0.9.G.1
	<ul>
		<li>Modules' private members are now truly private, unlike the other members, they are not visible to the calling struct, and their names will not collide with other names declared in the struct.</li>
	</ul>
	</li>
	<li>0.9.G.0
	<ul>
		<li>Added Modules and thistype.</li>
		<li>Will now call the optimize phase after PJass, as it was always intended, this should prevent some crashes during optimizations.</li>
		<li>Functions can now use .name in a similar way to methods.</li>
		<li>Fixed a bug that made child structs ignore the parent's storage size if a constant was used.</li>
		<li>Fixed a crash when the user attempts to assign a static array member.</li>
	</ul>
	</li>
	<li>0.9.F.7
	<ul>
		<li>$ Is now supported as hexadecimal prefix in integers - turns out wc3 always did.</li>
		<li>You can now tweak jasshelper.conf to set a different Jass compiler (i.e. change pjass.exe requirement into foojassc.exe).</li>
		<li>Fixed bugs related with displaying errors in blizzard.j / common.j in an unusual jasshelper setup is unusual like newgen's - several situations in which it would fail to show the correct file in the syntax error window/report have been fixed.</li>
		<li>clijasshelper will now specify the script file in which the errors were found.</li>
	</ul>
	</li>
	<li>0.9.F.6
	<ul>
		<li>jasshelper will avoid using TriggerEvaluate when the evaluated function/method does not contain function calls.</li>
		<li>function interfaces will consider all custom types as integers when comparing for validity, later it will have some type safety (i.e. you will not be able to use a integer in place of a struct, but you would be able to do the opposite) but for now it is type unsafe, use with care.</li>
		<li>member declarations with odd characters between the type and the name are now reported as syntax errors.</li>
		<li>static 2d arrays used to calculate their storage space incorrectly which caused issues like them not using get/set functions correctly, this has been fixed.</li>
		<li>It is not anymore possible to declare a member variable with the same name as a method operator.</li>
		<li>Fixed a documentation bug in the section about interfaces.</li>
	</ul>
	</li>
	<li>0.9.F.5
	<ul>
		<li>Old OS/X line breaks are now supported in input .j files, this would most likely be useless to everyone unless a bugged text editor saves the file using those...</li>
		<li>Fixed a crash bug introduced in 0.9.F.4 related with structs that extend interfaces/stub methods and don't <i>override</i> the method.</li>
	</ul>
	</li>
	<li>0.9.F.4
	<ul>
		<li>stub on a childless struct is not going to cause a syntax error anymore.</li>
		<li>The getType() method can be called on any struct instance.</li>
	</ul>
	</li>
	<li>0.9.F.3
	<ul>
		<li>More stub related bug fixes.</li>
	</ul>
	</li>
	<li>0.9.F.2
	<ul>
		<li>Fixed a bug when using super on methods that had arguments.</li>
		<li>Fixed a bug with bigarray.size using an undefined type which caused some type comparisons errors.</li>
	</ul>
	</li>
	<li>0.9.F.1
	<ul>
		<li>Fixed some bugs with stub methods on structs that extended interfaces.</li>
		<li>clijasshelper?</li>
	</ul>
	</li>
	<li>0.9.F.0
	<ul>
		<li>Fixed the return bug detector, there will not be false possitives, which means more functions will be inlined.</li>
		<li>Added stub methods.</li>
		<li>Added super.</li>
	</ul>
	</li>
	<li>0.9.E.1
	<ul>
		<li>Fixed issue with operator priority in result code of using 2D arrays.</li>
		<li>Fixed compile error caused by .execute on static methods with arguments.</li>
		<li>Fixed an usual chance to incorrectly inline return bug exploiters.</li>
		<li>Single-line return bug exploiters now recognized as non-state changing functions by the inliner (Increases chance to inline certain functions).</li>
		<li>dynamic array declarations now report garbage code after the end of the declaration.</li>
		<li>Fixed a bug with scope initializers making a next library unable to have nested scopes.</li>
		<li>Array structs can now have a max size specifier after "array".</li>
		<li>Fixed a readme bug, it incorreclty stated the command line arguments order.</li>
	</ul>
	</li>
	<li>0.9.E.0
	<ul>
		<li>Added --macromode.</li>
		<li>Added method.exists.</li>
		<li>Added 2D global arrays (and 2D static array members)</li>
		<li>Extra text after certain array size declaration is not ignored anymore (a correct syntax error now appears)</li>
		<li>Fixed certain readme bugs.</li>
	</ul>
	</li>
	<li>0.9.D.3
	<ul>
		<li>Array structs now work as intended.</li>
		<li>Fixed yet another regression with method calls.</li>
	</ul>
	</li>
	<li>0.9.D.2: -Fixed a [list out of bounds] error when using .method() syntax.</li>
	<li>0.9.D.1
	<ul>
		<li>Non-static methods that take no arguments are possible to be called again i.e: .destroy().</li>
		<li>Delegate cycles will now cause a crypting syntax error, which is better than jasshelper overflowing the stack.</li>
	</ul>
	</li>
	<li>0.9.D.0
	<ul>
		<li>Added delegate.</li>
		<li>Added functionname for function pointer values.</li>
		<li>Added a way to get the return value of .name= and []= assignment operators.</li>
		<li>Added extends array.</li>
	</ul>
	</li>
	<li>0.9.C.1
	<ul>
		<li>Fixed a problem caused by waits inside library initializers, they prevented other library initializers from running.</li>
		<li>SLK cells with either - or _ as ignored, whitespace inside these cells is also ignored.</li>
		<li>Fixed syntax errors caused by international compatibility issues in certain setups.</li>
	</ul>
	</li>
	<li>0.9.C.0
	<ul>
		<li>Fixed a crash that happened if you attempted to assign a method. (set x.create=2 )?</li>
		<li>Fixed a bug that made children struct cause syntax errors if the parent uses extra space.</li>
		<li>Fixed a conflict between --nopreprocessor and using script arguments (the script used to be ignored)</li>
		<li>Fixed a conflict between --nopreprocessor and --scriptonly though it would be nonsense to use both simultaneously anyway...</li>
		<li>Inline phase no longer gets confused by control characters in strings.</li>
		<li>Inline phase no longer gets confused by control characters in strings (Both of these were meant to handle those things correctly, but there were small bugs in certain functions that made the provisions fail)</li>
		<li>Added the colon operator.</li>
		<li>Improved the syntax error caused by getFromKey not taking a single argument</li>
		<li>Fixed a bug with the SLK parser that made it unable to parse SLKs with UNIX (normal) linebreaks.</li>
		<li>Certain loaddata syntax errors will now also point to the location of the related struct/member.</li>
		<li>Cells with - are now ignored (that would have created bad syntax anyway).</li>
		<li>Compatibility with yet another odd quote sequence used by openoffice in SLKs.</li>
		<li>Given how absurdly hard and tool-dependent it is to use " in a SLK cell, jasshelper will now automatically add "" to cells in columns for string-typed cells that don't have them. (unless it is - or an empty cell, in which case it will use the default value, which is probably "" anyway)</li>
		<li>Similarly, If a column's field is of integer type, it will add '' automatically to non-integer values of length 4 or 1 inside cells.</li>
		<li>Code generated by loaddata is now split in function batches of 100 loaded structs each (each using its own thread), long functions cause PJass errors and might also cause thread crashes...</li>
		<li>If you use //! import from an imported file, you are able to use relative file paths based on the importing file's location.</li>
		<li>Backwards incompatibility: I hope no one was using variables in SLK cells. It should still work if the type is not string or integer, if the type is integer, variables would still work provided their name length is not 4 or 1.</li>
	</ul>
	</li>
	<li>0.9.B.1
	<ul>
		<li>Once again struct members can be initialized.</li>
	</ul>
	</li>
	<li>0.9.B.0
	<ul>
		<li>Fixed a bug with the first jasshelper phase which used to cut the last line of an input file potentially causing problems if WE decides not to print a last empty line (which apparently happens sometimes).</li>
		<li>Fixed a chance for access violation after the structs phase finishes.</li>
		<li>Jasshelper no longer ignores extra code after a struct member declaration (It now shows an error).</li>
		<li>Jasshelper no longer ignores extra code after a local variable declaration (It now shows an error).</li>
		<li>Structs now allow sized static array members.</li>
		<li>Added //! novjass and //! endnovjass.</li>
		<li>Added --scriptonly and --warcity</li>
		<li>global variable addition order is now affected by library requirements.</li>
		<li>Fixed a couple of "&amp;aquot;" bugs in the readme file.</li>
		<li>The readme file comes with description about jasshelper's command line options.</li>
	</ul>
	</li>
	<li>0.9.A.0
	<ul>
		<li>Added inline phase and --nooptimize</li>
	</ul>
	</li>
	<li>0.9.9.B
	<ul>
		<li>Fixed a bug that would cause syntax errors when two or more scopes got initializers.</li>
		<li>Maximum extended array size limit increased to 409550.</li>
		<li>Dynamic arrays allow sizes smaller than array's storage limit / 8.</li>
	</ul>
	</li>
	<li>0.9.9.A
	<ul>
		<li>Fixed yet another bug that prevented f__arg_this from being created.</li>
		<li>Scopes now use normal calls instead of ExecuteFunc for initializers.</li>
		<li>Updated readme, scope initializers are mentioned, made it aware //! for libraries and scopes now cause a syntax error.</li>
	</ul>
	</li>
	<li>0.9.9.9
	<ul>
		<li>Hopefully fixed onDestroy issues with extends and similar.</li>
		<li>Fixed memory corruption when using [] on structs/interfaces to increase index limit.</li>
		<li>Added big sized global arrays.</li>
		<li>Library declarations more likely to survive comments.</li>
		<li>Fixed hang outs related to wrong use of extends.</li>
		<li>Fixed bug with defaults on methods that return custom types.</li>
		<li>Scopes can have initializers.</li>
	</ul>
	</li>
	<li>0.9.9.8 (test release)
	<ul>
		<li>Fixed a bug with f__arg_this not being declared when required if extends is involved.</li>
		<li>Fixed a crash related to misplaced endscope inside a library.</li>
		<li>Fixed a bug with array members in child structs, possibly "leaking", which means they did not get recycled properly and the struct would eventually malfunction.</li>
		<li>Can declare methods to replace variable access and write operators (method operator name and method operator name=)</li>
		<li>"member is private" syntax error now also shows the name of the involved struct.</li>
		<li>Access violations will report a related line of code if possible</li>
		<li>Can setup max index space on dynamic arrays and structs ( type arrayname extends typename array [ instancesize, spacerequired ] )( struct name[spacerequired] )( interface name[spacerequired]</li>
		<li>In order for last feature to work I have to modiffy plenty of things, expect an unstable version, releasing it so I could get free testing...</li>
	</ul>
	</li>
	<li>0.9.9.7
	<ul>
		<li>Fixed a bug with methods, pseudo inheritance and interfaces that is just too hard to explain.</li>
		<li>Fixed a bug with third generation (and above) child structs and array members.</li>
		<li>Scopes and libraries may now use numbers in their names (Still not _).</li>
		<li>External command line length limit extended to 1000.</li>
	</ul>
	</li>
	<li>0.9.9.6
	<ul>
		<li>Fixed a bug with onDestroy if it contains calls to methods from other structs and is used on an struct extending another struct.</li>
		<li>[] and []= operators can also be declared as static.</li>
		<li>Order of addition of libraries that don't extend each others is now sorted by name.</li>
		<li>empty interfaces or onDestroy methods are assigned to null rather than not assigning their arrays, it probably was all right but this sounds better.</li>
	</ul>
	</li>
	<li>0.9.9.5
	<ul>
		<li>Fixed more bugs related to onDestroy and extends.</li>
		<li>Fixed various bugs relating to syntax errors and library declarations.</li>
		<li>Fixed a certain line off-set present for syntax errors after files are imported.</li>
		<li>Fixed a readme bug with the changelog.</li>
	</ul>
	</li>
	<li>0.9.9.4
	<ul>
		<li>Fixed a bug with static methods that return custom types and require evaluate.</li>
		<li>Fixed plenty of bugs related to "running" undeclared textmacros.</li>
		<li>Fixed plenty of bugs related to onDestroy methods when inheritance or interfaces are involved.</li>
		<li>Fixed an access violation crash when the [] operator is used on methods</li>
		<li>Fixed probable (local-not-set-to-null) memory leak with function interfaces, methods called from above their declaration, evaluate, execute and function interfaces</li>
		<li>Long external calls will now popup an error instead of crashing jasshelper.</li>
		<li>Added onInit method support for structs.</li>
	</ul>
	</li>
	<li>0.9.9.3
	<ul>
		<li>Fixed a bug with return statements in interface functions that return nothing</li>
		<li>Fixed a crash with --nopreprocessor that introduced a long ago.</li>
	</ul>
	</li>
	<li>0.9.9.2
	<ul>
		<li>Fixed a major bug causing desyncs (All functions generated by jasshelper that are passed to Condition() will have a boolean return value)</li>
		<li>struct.typeid now returns an accurate integer not dependant on parent ids and is replaced by a constant added to the map script instead of a single number.</li>
	</ul>
	</li>
	<li>0.9.9.1
	<ul>
		<li>Fixed a bug with static methods that return custom types and required evaluate mode, causing some pjass parse errors.</li>
		<li>Structs may now extend other structs.</li>
		<li>Interfaces are now allowed to declare a rule so that constructors of the interface's children do not declare a create method that takes arguments.</li>
		<li>interface.create() will now return 0 when there is attempt to call the private allocate() method.</li>
	</ul>
	</li>
	<li>0.9.9.0
	<ul>
		<li>Fixed a critical error causing infinite loops when there were external commands used for grimoire version.</li>
		<li>Improved Wine compatibility again, should work with more versions of Wine including the newest.</li>
		<li>Grimoire version's compile error window used to have a chance to look akward under certain windows UI settings, this problem is fixed.</li>
	</ul>
	</li>
	<li>0.9.8.9
	<ul>
		<li>Documented inject.</li>
		<li>Added information about problems related to sync natives and methods/evaluate().</li>
		<li>Improved the error message given if InitBlizzard() is not present in the main function.</li>
		<li>New command line option to use an external war3map.j instead of the one found in the map.</li>
		<li>Improved compatibility with WINE, at least on the recent WINE versions I have tested jasshelper.exe and it can compile a map fine.</li>
		<li>Added some syntax errors for maluse of dynamic arrays or array members</li>
		<li>Fixed issues with commented-out/incomplete return statements inside certain methods or functions.</li>
		<li>private or public are ignored when using on scope declarations, used to silently cause other bugs before.</li>
		<li>Made usage of public and private more strict to prevent bugs (Instead there would be syntax errors)</li>
		<li>Added: keyword</li>
		<li>[scope symbol redeclared] syntax error will now also specify the first declaration of the symbol.</li>
		<li>Made certain statements more strict, some used to allow extra text after the statement (scope or globals for example)</li>
		<li>Made a syntax error related to libraries more understandable.</li>
		<li>Struct member initializers may now use . syntax (it used not to parse them)</li>
		<li>Added a .name field for static methods, returns the string of the generated function name.</li>
		<li>interfaces can use .create if given a typeid value.</li>
	</ul>
	</li>
	<li>0.9.8.8
	<ul>
		<li>Fixed plenty of issues with parsing of runtextmacros and handling of syntax errors in textmacros.</li>
		<li>Child structs may override the initia default values of members of the interface.</li>
		<li>structs allocation needs one less array and is a littler faster.</li>
		<li>Improved error message given when someone makes an attempt to make an struct that extends an struct.</li>
		<li>Can use .execute() on methods.</li>
	</ul>
	</li>
	<li>0.9.8.7
	<ul>
		<li>Fixed a bug that caused issues with functions that returned custom types.</li>
	</ul>
	</li>
	<li>0.9.8.6
	<ul>
		<li>Fixed a bug with scope private/public members used inside an struct.</li>
		<li>Optimized performance of struct stage.</li>
		<li>Compiler will now prevent name conflicts and rais errors if it finds them, these prevent bugs later but it is possible that an old name conflict in your map survived for a lot of time and this new jasshelper version will popup a previously unheard error for that map.</li>
		<li>Undeclared InitTrig functions are ignored instead of poping syntax errors, this allow for cleaner usage of the trigger editor with libraries.</li>
	</ul>
	</li>
	<li>0.9.8.5
	<ul>
		<li>Added defaults keyword for interface methods.</li>
		<li>Fixed some bugs with the installer for WEHelper, should be easier to install to 1.8 although you still have to specify the path.</li>
		<li>Fixed a bug that made jasshelper unable to recognize hex integers if they had lower case letters.</li>
		<li>Formatted the manual a little.</li>
	</ul>
	</li>
	<li>0.9.8.4
	<ul>
		<li>Fixed a bug with interface extending structs with multiple array members.</li>
		<li>Fixed a bug with international characters inside strings.</li>
		<li>Fixed some scoping issues, locals are now handled correctly by the structs convertor.</li>
		<li>Added getType() and typeid for interfaces.</li>
	</ul>
	</li>
	<li>0.9.8.3
	<ul>
		<li>Fixed a possible compiler crash.</li>
		<li>Fixed a bug that made function interfaces unable to have arguments of custom types.</li>
		<li>Modified the way grimoire version works in many ways, just replacing the executable will not work. A new version of newgen pack is released which you should update, else you may also have to wait for a new grimoire version.</li>
	</ul>
	</li>
	<li>0.9.8.2
	<ul>
		<li>Fixed a 0.9.8.0 bug that prevented dynamic arrays from being used.</li>
	</ul>
	</li>
	<li>0.9.8.1
	<ul>
		<li>Fixed a bug with function evaluate/execute methods using wrong variables.</li>
	</ul>
	</li>
	<li>0.9.8.0
	<ul>
		<li>Structs now come with an internal private static method called allocate that does what .create used to do.</li>
		<li>If no correct static method create is declared within an struct body, a default one which calls .allocate is added.</li>
		<li></li>
		<li>Functions are now objects, you can call methods evaluate and execute on function names no matter the position of the function declaration, execute() runs the function in another thread.</li>
		<li>Added function interfaces, this allows function variables and other fun stuff.</li>
	</ul>
	</li>
	<li>0.9.7.4
	<ul>
		<li>Fixed bugs with array members in structs that extend interfaces.</li>
		<li>Fixed syntax error bug with calling .destroy above an onDestroy declaration.</li>
		<li>Improved performance of interfaces (reduced a function call when calling a method, and improved constructor performance).</li>
		<li>Also improved performance of methods when called from above their declaration</li>
	</ul>
	</li>
	<li>0.9.7.3
	<ul>
		<li>structs may now have array members.</li>
		<li>Constant integer variables may now be used for size of dynamic array and array member declarations.</li>
	</ul>
	</li>
	<li>0.9.7.2
	<ul>
		<li>&lt;, &gt; comparissons between zero and an struct type are allowed again.</li>
		<li>Fixed logic flaw in implementation of &lt; operator for interfaces that made them unable to use it.</li>
		<li>Added SCOPE_PREFIX and SCOPE_PRIVATE, assist to use ExecuteFunc / real variable events on scope private/public members, and are also useful for debugging.</li>
		<li>Public InitTrig function is now translated to InitTrig_ScopeName instead of ScopeName_InitTrig (makes some stuff way easier, specially for JESP spells)</li>
		<li>Grimoire version now writes logs in a logs subfolder as compliance with newest grimoire version.</li>
		<li>Fixed multiple bugs related to handling SLKs saved by certain versions of MSExcel</li>
	</ul>
	</li>
	<li>0.9.7.1
	<ul>
		<li>Fixed a major bug introduced on 0.9.7.0 that made interfaces useless.</li>
	</ul>
	</li>
	<li>0.9.7.0
	<ul>
		<li>Fixed bug with big string literals.</li>
		<li>Fixed major bug with the way dynamic array indexes are handled.</li>
		<li>Added an integer() typecast operator (for structs and dynamic arrays only, we'll soon have an actual typecast operator for native types).</li>
		<li>Added operator overloading for [] (both get and set) and &gt;</li>
		<li>Fixed a bug with some syntax error showing extra, debugging information that was supposed to be removed</li>
		<li>Structs extending an interface no longer have to be declared after the interface</li>
		<li>Will now show a proper syntax error if a method derived from interface is declared as static, instead of generating bugged code.</li>
	</ul>
	</li>
	<li>0.9.6.3
	<ul>
		<li>Fixed requirement of whitespace before [ in dynamic array declarations.</li>
		<li>Fixed some issues with nested methods causing misleading syntax errors.</li>
		<li>Fixed some problems with local variables/arguments with the same name of previous local variables/arguments that were of custom types while the new ones were not (causing some confusion/odd syntax errors).</li>
		<li>Fixed a probable issue with dynamic array indexes</li>
		<li>Added instructions about how to update jasshelper in newgen pack</li>
	</ul>
	</li>
	<li>0.9.6.2
	<ul>
		<li>Fixed syntax errors that could appear if there were special characters in strings or comments.</li>
	</ul>
	</li>
	<li>0.9.6.1
	<ul>
		<li>(WEHelper only) fixed a bug that made worleditor unable to ever finish compiling.</li>
	</ul>
	</li>
	<li>0.9.6.0
	<ul>
		<li>Added dynamic arrays (type name extends anothertype array [size]).</li>
		<li>Added typecast operators (for struct types, soon we will have them for all the types).</li>
		<li>It might now detect some few syntax errors before the pjass stage (prevents confusion when there are errors in code that is already compiled by JassHelper)</li>
		<li>Instances might also call static members</li>
		<li>Fixed a bug with the readme's html</li>
	</ul>
	</li>
	<li>0.9.5.2
	<ul>
		<li>Fixed a bug with struct methods that had more than one argument of different types.</li>
		<li>JassHelper now repeats its process after external tools are executed.</li>
		<li>Added an interfaces demo.</li>
	</ul>
	</li>
	<li>0.9.5.1
	<ul>
		<li>Fixed a bug that could cause [Undeclared variable f__arg_this] pjass errors when saving</li>
		<li>Fixed a bug with //! import not importing the last line of the file.</li>
		<li>Fixed a bug with //! import not being able to import a file if quotes weren't used for the path and there were comments after the command (may happen if import is the last line of a world editor [trigger]])</li>
	</ul>
	</li>
	<li>0.9.5.0
	<ul>
		<li>Can now convert slk files to struct assignments with the //! loaddata preprocessor.</li>
		<li>Added the //! external preprocessor which allows you to configure jasshelper to run command line tools, the way the command line tools have to work is very specific so if you should check out the manual if you are interested in making them.</li>
		<li>WEHelper's plugin has now dialogs to configure lookup folders and external tools. Grimoire's mapcompiler can take advantage of a .conf file.</li>
		<li>Grimoire mapcompiler is now able to run wewarlock once configured correctly.</li>
		<li>Jasshelper's import can now be used in WEHelper if WEHelper's is disabled. The advantage you can get from it is the ability to configure the lookup folders.</li>
		<li>Fixed some terrible typos in the interfaces explanation of the readme</li>
	</ul>
	</li>
	<li>0.9.4.4
	<ul>
		<li>Fixed a compiler crash when there was an struct (something) extends (something else) when the parent struct name wasn't declared yet.</li>
		<li>Fixed a chance for the struct usage to generate game-crashing code.</li>
	</ul>
	</li>
	<li>0.9.4.3
	<ul>
		<li>Fixed a bad bug that could cause access violations if textmacros are used extensively</li>
		<li>Fixed a bug with public/private members not being replaced accordingly on lines that had a / in them.</li>
		<li>Grimoire version allows relatives paths for //! import , you can specify where to look for files in the newly set mapcompiler.conf file</li>
	</ul>
	</li>
	<li>0.9.4.2
	<ul>
		<li>It is again safe to call jasshelper twice. (Fixes some issues with testmap and WEHelper)</li>
		<li>Grimoire version now includes a beta of //! import , use //! import on complete paths only (for 例子 //! import c:\goo.j )</li>
	</ul>
	</li>
	<li>0.9.4.1
	<ul>
		<li>Documented 0.9.4 features.</li>
		<li>Fixed a bug with static methods on interface extending structs causing PJASS errors.</li>
		<li>Fixed a bug with static methods with no arguments having a chance to cause compile errors that to make matters worse were not detectable by PJASS.</li>
		<li>Fixed a bug with default values being ignored on structs that extend interfaces.</li>
	</ul>
	</li>
	<li>0.9.4
	<ul>
		<li>structs can now have methods.</li>
		<li>Added interfaces</li>
		<li>Added //! inject</li>
		<li>Again, documentation of new features would take a while</li>
		<li>Compiler for grimoire now got a progress bar and uses SFMPQ.dll directly instead of mpqutils, which should be faster and also be compatible with a later version of grimoire which will remove mpqutils and replace them with mpq2k.</li>
	</ul>
	</li>
	<li>0.9.3
	<ul>
		<li>Fixed multiple bugs in compatibility between scopes and structs.</li>
		<li>Fixed a minor issue with the grimoire compiler.</li>
		<li>Updated some sections of the manual, added more info about structs.</li>
	</ul>
	</li>
	<li>0.9.2
	<ul>
		<li>Fixed grave bugs probability when many structs were used</li>
		<li>Destroying the 0 struct will do nothing instead of sending it to the recycle stack.</li>
		<li>Include compiler to be used by grimoire's wehack.dll.</li>
		<li>Documented 0.9.0 aditions.</li>
	</ul>
	</li>
	<li>0.9.1
	<ul>
		<li>Fixed a wrong syntax error when comments with triple / were present</li>
		<li>Fixed a syntax error caused by having dot characters inside comments</li>
		<li>The new additions to the syntax are not documented yet</li>
	</ul>
	</li>
	<li>0.9.0
	<ul>
		<li>Fixed some wrong instructions that could end up causing access violations</li>
		<li>Fixed a bug with some textmacro declaration errors giving the wrong line number.</li>
		<li>Fixed a bug that made libraries unable to have child scopes unlike what the documentation said.</li>
		<li>Fixed a bug with private/public that made it unable to rename identifiers correctly after single / characters.</li>
		<li>Added library_once</li>
		<li>Added textmacro_once</li>
		<li>Added structs, dynamically allocated object types. Seriously.</li>
		<li>The new additions to the syntax are not documented yet</li>
	</ul>
	</li>
	<li>0.8.0
	<ul>
		<li>Added //! textmacro support.</li>
		<li>Fixed a bug with private/public that didn't process global variables correctly if they were initialized and had = stuck to the name.</li>
	</ul>
	</li>
	<li>0.7.0
	<ul>
		<li>Better handling of some syntax errors.</li>
		<li>Nested scopes are now legal.</li>
		<li>Added the public keyword.</li>
		<li>Cut the file size.</li>
	</ul>
	</li>
	<li>0.6.1 : Added installer for the WEHelper plugin.</li>
	<li>0.6
	<ul>
		<li>Added private keyword and //! scope.</li>
		<li>Various optimizations, specially for the plugin edition.</li>
		<li>JASSHelper is called again after WEWarlock, so you can use features like debug or private in files called by //! require</li>
	</ul>
	</li>
	<li>0.5.2: For WEHelper 1.5.2</li>
	<li>0.5
	<ul>
		<li>Fixed wrong error messages in the case of unclosed strings causing issues.</li>
		<li>Fixed a bug that made debug cut the last character</li>
	</ul>
	</li>
	<li>0.4
	<ul>
		<li>Fixed a bug that made this preprocessor unable to recognize globals//comment and endglobals//comment.</li>
		<li>Removed the progress bar from WEHelper plugin</li>
		<li>Added WEWarlock support to WEHelper plugin (Can call the WEWarlock compiler, and you can use wewarlock's features in your map by just saving.).</li>
		<li>For WEHelper 1.5.1</li>
	</ul>
	</li>
	<li>0.3
	<ul>
		<li>initializer will now call the init functions AFTER call InitBlizzard() allowing to use blizzard globals on init functions.</li>
		<li>requires and uses also work in the place of needs</li>
		<li>For WEHelper 1.5</li>
	</ul>
	</li>
	<li>0.2: (initial public release)</li>
</ul>
</div>
									</div>
								</div>
								</body>